Quantcast
Channel: Extended WPF Toolkit™ Community Edition
Viewing all articles
Browse latest Browse all 4964

New Post: How to change dynamically in code readonly property of a propertyItem of a PropertyGrid

$
0
0
up,

I found a way to do that :
public void SetPropertyReadOnly(PropertyItem pProperty, bool pValue)
 {
            PropertyDescriptor descriptor = pProperty.PropertyDescriptor;
            ReadOnlyAttribute attribute = (ReadOnlyAttribute)
                                                  descriptor.Attributes[typeof(ReadOnlyAttribute)];
            FieldInfo fieldToChange = attribute.GetType().GetField("isReadOnly",
                                             System.Reflection.BindingFlags.NonPublic |
                                             System.Reflection.BindingFlags.Instance);
            fieldToChange.SetValue(attribute, pValue);
 }
I don't know if it's the best solution but it works!

Viewing all articles
Browse latest Browse all 4964

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>