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

New Post: PropertyGrid: Dynamically add Properties or Hide Properties on Runtime.

$
0
0
Good morning,

I'm searching for a way to dynamically hide properties that are 'String.IsNullOrEmpty'.
I tried using reflection:
  private void SetBrowsableProperty(string strPropertyName, bool bIsBrowsable)
        {

            PropertyDescriptor propertyDesc = TypeDescriptor.GetProperties(GetType())[strPropertyName];

            BrowsableAttribute attribute = (BrowsableAttribute)propertyDesc.Attributes[typeof(BrowsableAttribute)];
            FieldInfo fiedInfo = attribute.GetType().GetField("Browsable", BindingFlags.IgnoreCase | BindingFlags.NonPublic | BindingFlags.Instance);

            fiedInfo.SetValue(attribute, bIsBrowsable);
        }
..to set the Browsable Attribute, but that causes the Properties in the PropertyGrid to dissapear completely, independent if they have a value or not.

Any help is highly appreciated.

Viewing all articles
Browse latest Browse all 4964

Trending Articles



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