Cannot set property to readonly when using custom editor
Hello Support,
I wanted to set a readonly double field to have 4 decimal places so I've followed examples to use a custom editor. However when the custom editor is applied the readonly attribute is not applied.
Here is a sample of my code:
[Editor(typeof(double), typeof(DoubleNumberEditor))] public struct LevelSet { [ReadOnly(true)] public double VIH { get; set; } }
public class DoubleNumberEditor : DoubleTextBoxEditor { DoubleTextBox _doubleTextBox; public override void Attach(PropertyViewItem property, PropertyItem info) { if (info.CanWrite) { var binding = new Binding("Value") { Mode = BindingMode.TwoWay, Source = info, ValidatesOnExceptions = true, ValidatesOnDataErrors = true }; BindingOperations.SetBinding(_doubleTextBox, DoubleTextBox.ValueProperty, binding); } else { var binding = new Binding("Value") { Source = info, ValidatesOnExceptions = true, ValidatesOnDataErrors = true }; BindingOperations.SetBinding(_doubleTextBox, DoubleTextBox.ValueProperty, binding); } }
public override object Create(PropertyInfo propertyInfo) { _doubleTextBox = new DoubleTextBox() { GroupSeperatorEnabled = false, NumberDecimalDigits = 4, }; return _doubleTextBox; } }
Could you show me how to make the custom editor for the double text property be readonly?
Thanks,
Alan
Thanks for contacting syncfusion support,
We have checked the reported query from our end. We can be able to set the read only property and prepare the sample for the reference in given below location.
Sample: https://www.syncfusion.com/downloads/support/forum/167190/ze/CustomEditor_(2)152978676
Please ensure our sample and let us know our procedure is same as yours if not please share the issue reproducing project file and the video for the same. It will be helpful for us to proceed further and provide a prompt solution on this.
Regards,
Sudharsan
Hi Sudharsan,
Thanks for the sample, however it does not demonstrate the problem I have: the Employee model is not using the custom editor "DoubleNumberEditor"; I want to have a readonly property of double type, with 4 decimal places.
For example, if I add this new property to the Employee model:
[ReadOnly(true)] [Editor(typeof(double), typeof(DoubleNumberEditor))] public double NumKids { get; set; }
I get the following output:
As you can see the NumKids property using the custom editor is still enabled.
Thanks,
Alan
Thanks for update,
We have checked the reported issue that “ReadOnly when using CustomEditor” from our end and to achieve the requirement. We have prepared the sample for the reference in given below location.
Sample: https://www.syncfusion.com/downloads/support/forum/167190/ze/CustomEditor1503055742
Regards,
Hello,
In your sample it is not using the custom editor for the doubles type. What I'm looking for is a doubles property with 4 decimal places AND is readonly. Once you update the ViewModel to the following, the ReadOnly(true) attribute on the NumKids property is not applied:
public ViewModel() { SelectedEmployee = new Employee() { Age = 25, Name = "mark", Experience = 5, EmailID = "mark@gt",NumKids=9135 }; CustomEditor editor = new CustomEditor(); editor.Editor = new DoubleNumberEditor(); editor.HasPropertyType = true; editor.PropertyType = typeof(double); CustomEditorCollection.Add(editor); }
Thanks for the update,
From our end, we have checked the reported issue that “custom editor ReadOnly not applied for the property”. As you’re using the custom editor, we may change the editor control needs by using the attach, create method. So, We have modified the sample to achieve the requirement. Please check the sample and documentation from the below location,
Sample: https://www.syncfusion.com/downloads/support/forum/167190/ze/CustomEditor_DoubleTextBox541058999
Documentation: https://help.syncfusion.com/wpf/propertygrid/customeditor-support
Thank you this is just what I needed.
Regards,
Alan
Regards,
Sudharsan
- 7 Replies
- 2 Participants
-
AK Alan Kin
- Jul 13, 2021 02:45 PM UTC
- Jul 19, 2021 04:15 AM UTC