Property description fails to update on instance change

Jan 5, 2011 at 7:55 PM

This issue doesn't appear in the WpgDemo  because they don't work with properties that have a description. In my application, I have instances that implement  ICustomTypeDescriptor and the properties have a Description. Of course you could have properties with static descriptions like:

        [System.ComponentModel.Description("something")]

In any event, when the instance changed, then description would not get updated. I fixed that by changing PropertyGrid.cs as follows:

Added method to WPG/PropertyGrid.cs:

        void ClearDescription()
        {
            if (this.Template != null)
            {
                object myDescriptionField = Template.FindName("Part_PropertyName", this);

                if (myDescriptionField != null && myDescriptionField is TextBlock)
                    ((TextBlock)myDescriptionField).Text = "";

                object myNameField = Template.FindName("Part_PropertyDescription", this);

                if (myNameField != null && myNameField is TextBlock)
                    ((TextBlock)myNameField).Text = "";
            }
        }

And call this method at the top of Refresh():

public void Refresh()

{

ClearDescription();

...

I freely admit that I didn't think through all possible use cases and just wrote up something that would work in my case, so you might want to review this a little before using it.

 

Coordinator
Jan 5, 2011 at 11:57 PM
poppy wrote:

This issue doesn't appear in the WpgDemo  because they don't work with properties that have a description. In my application, I have instances that implement  ICustomTypeDescriptor and the properties have a Description. Of course you could have properties with static descriptions like:

        [System.ComponentModel.Description("something")]

In any event, when the instance changed, then description would not get updated. I fixed that by changing PropertyGrid.cs as follows:

Added method to WPG/PropertyGrid.cs:

        void ClearDescription()
        {
            if (this.Template != null)
            {
                object myDescriptionField = Template.FindName("Part_PropertyName", this);

                if (myDescriptionField != null && myDescriptionField is TextBlock)
                    ((TextBlock)myDescriptionField).Text = "";

                object myNameField = Template.FindName("Part_PropertyDescription", this);

                if (myNameField != null && myNameField is TextBlock)
                    ((TextBlock)myNameField).Text = "";
            }
        }

And call this method at the top of Refresh():

public void Refresh()

{

ClearDescription();

...

I freely admit that I didn't think through all possible use cases and just wrote up something that would work in my case, so you might want to review this a little before using it.

 

I fixed this, but in a complete other way.

Now I have a public Property of the selected Property, and i use Databinding on this Property.

When the Instance changes, the selected Property is cleared!