This project has moved and is read-only. For the latest updates, please go here.

PropertyGrid and RefreshProperties attribute

Nov 3, 2013 at 7:42 PM
I am looking at making certain properties dynamic based on other properties. I am using the ICustomTypeDescriptor for the object which is the SelectedObject.

Typically RefreshProperties attribute can be used on any property - this can set the browsable/readonly attribute on other properties. Apparently RefreshProperties does not work correctly with the property grid in the Extended WPF Toolkit.
Developer
Nov 4, 2013 at 2:32 PM
Hi,

if you are looking for a feature like this one : https://wpftoolkit.codeplex.com/workitem/20070, please vote for it.

Thanks
Nov 4, 2013 at 4:03 PM
No - it is not like the one you mentioned. The one that I am talking about is related to a case like the one mentioned below

Class Car
{
[Browsable(true)]
[RefreshProperties(RefreshAll)]
bool Trigger {get; set; }

[DynamicBrowsable("Trigger")]
string Prop1 {get; set; }

[DynamicBrowsable("Trigger")]
string Prop2 {get; set; }
}

Basically, DynamicBrowsable attribute is something that I created which depends on the Trigger property's value. If Trigger value is true - Prop1 and Prop2 will be displayed.

Bottomline is, if a property is marked with RefreshProperties attribute - we need to re-evaluate the properties that gets displayed in the property grid. This happens in the Microsoft released property grid for win forms, but this does not work for the WPF version here.
Developer
Nov 5, 2013 at 1:03 PM
Hi,

Thanks for description. The issue https://wpftoolkit.codeplex.com/workitem/20385 has been created.
Dec 29, 2014 at 10:11 AM
I don't know whether it's right or not, but I solved the problem this way:
in class ObjectContainerHelperBase I added two metods:
        private bool HasRefreshPropertiesAttribute(PropertyItem propertyItem)
        {
            RefreshPropertiesAttribute attr = propertyItem.DescriptorDefinition.PropertyDescriptor.Attributes.OfType<RefreshPropertiesAttribute>().FirstOrDefault();
            return attr != null && attr.RefreshProperties == RefreshProperties.All;
        }

        private void OnRefreshProperties(object sender, EventArgs e) { RegenerateProperties(); }
and modify metod RegenerateProperties (see lines marked as "// new line"):
        private void RegenerateProperties()
        {
            ...
            //Remove the event callback from the previous children (if any)
            foreach (var propertyItem in PropertyItems)
            {
                propertyItem.PropertyChanged -= OnChildrenPropertyChanged;

                if (HasRefreshPropertiesAttribute(propertyItem)) // new line
                    propertyItem.DescriptorDefinition.PropertyDescriptor.RemoveValueChanged(propertyItem.Instance, OnRefreshProperties); // new line
            }
            ...
            //Add the event callback to the new childrens
            foreach (var propertyItem in PropertyItems)
            {
                propertyItem.PropertyChanged += OnChildrenPropertyChanged;

                if (HasRefreshPropertiesAttribute(propertyItem)) // new line
                    propertyItem.DescriptorDefinition.PropertyDescriptor.AddValueChanged(propertyItem.Instance, OnRefreshProperties); // new line
            }
            ...