Hi guys,
Back in Nov-Dec 2016, you had added the ReadOnly property to ComboBox, which makes the reading of the control much easier compared to the grayed-out appearance of setting Enabled = false. The ReadOnly property is also there for TextBox. Is there the possibility of having this property for the Control base class? I suppose it would be a combination of the Enable = false functionality in C# with the Enable = true appearance in the Theme… But of course I might be wrong! 🙂
Best regards,
Alex
Hi Alex,
See answers below:
HTH
Best,
Luca
Hi Luca,
That’s it, your AppearenceKey method did the trick! So I added in my mixing the “readonly-checkbox”, “readonly-textbox” etc, and a ReadOnly property to my control container, which, when set to true loops over the controls and makes their Enabled = false and sets the appropriate AppearenceKey for each control type. Very nice method, and once more, respect for the flexibility and clarity of Wisej.
During this exercise a few questions came up.
And two features I saw:
Thanks,
Alex
Hi Alex,
Got it. Another option is to create a new key for disabled but not grayed controls. You can create something like “readonly-checkbox”, “readonly-textbox”, … inherit from the respective keys and now use the Enabled property. Assign the key to the control’s AppearanceKey property. Something like this, in a mixin:
“appearances”: {
“readonly-checkbox”: {
“inherit”:”checkbox”,
“states”: {
“disabled”: {
“styles”: {
// put styles for the disabled state.
},
“properties”: {
// put styles for the disabled state.
}
}
}
}
}
I haven’t tried this, and you may need to tweak it a bit.
Best,
Luca
Hi Luca,
Do you mean in option 1 is change the theme so the disable checkbox looks better (more contrast)?
And we just use Enable = True/False as now?
Hi Luca,
I must be missing something basic here… Let’s talk specifically about CheckBox, which does not have the ReadOnly property.
Option 1, if I go into ThemeBuilder, go to CheckBox and make the Disabled state look like the Default state (change the opacity), this would mean that all my checkboxes throughout my application will look as enabled. However, I want to have this only in a specific form, not for all checkboxes.
Option 2, if I add a ReadOnly property to the GroupBox containing a CheckBox and a TextBox. Then, iterate over controls in my container (the GroupBox) and check for ReadOnly. It is present for the TextBox and the TextBox is indeed set to ReadOnly = true, but it is not present for the CheckBox and nothing changes. What do I achieve this way? The CheckBox is still editable.
Best,
Alex
Got it. The Enabled property is inherited and allows you to enable/disable a container. The ReadOnly is specific. Some of the options could be to:
a) Modify the theme and change the disabled state, now it uses opacity to disable the entire control including child widgets;
b) Add a ReadOnly property to your containers (or add an extension method) and iterate the children of a container using a dynamic cast in a try/catch or using TypeDescriptor to get the “ReadyOnly” property.
HTH
Best,
Luca
Hi Luca,
Thanks for your answer. My “problem” is that I would like to show a form with various controls on it (textbox, datetimepicker, combobox, checkbox, groupbox, …) without allowing the user to do any changes. This is achieved with each control’s .Enabled = false, but the disabled controls are difficult to read as they are grayed out. That’s why I would like to have them all as ReadOnly, which, for TextBox and ComboBox at least, does not gray them out but effectively disables them.
Best,
Alex
Hi Alex,
Enabled and ReadOnly are treated differently. Enabled works for any control while ReadOnly is for editable controls and each editable control can be different (i.e. DataGrid or TextBox). There are base common classes when they share the base. In other words, ReadOnly in Control wouldn’t work.
You can read the property without having to cast using a dynamic object:
dynamic control = this.textBox1;
bool readOnly = control.ReadOnly;
Works regardless of the class. You get a binding error if the ReadOnly property is not found.
HTH
Best,
Luca
Please login first to submit.