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
Got it working.
The trick was to set the Browsable Attribute to true on all properties, then call the SetBrowsableProperty in the setter of the property.
        [Category("Projekt")]
        [PropertyOrder(1)]
        [DisplayName("Projectnumber")]
        [Browsable(true)]
        public string ProjectNumber
        {
            get
            {
                return _projectNumber;
            }
            set
            {
                _projectNumber = value;
                SetBrowsableProperty("ProjectNumber", !String.IsNullOrEmpty(_projectNumber));
            }
        }

        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);
        }


Viewing all articles
Browse latest Browse all 4964

Trending Articles



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