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
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
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); }
Thank you this is just what I needed.
Regards,
Alan