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

(PropertyGrid) Dynamic Visibility of Properties

Jul 13, 2012 at 4:18 PM

How can I hide and show properties in my codebehind for the same object?

For example, I have a product when its type is equal to "A" shows all the properties. When their type is equal to "B" hides the properties X, Y, Z of the PropertyGrid.

By the way, I would not only enable and disable editing of the property, so I can do.

Jul 20, 2012 at 7:53 PM

Campaign:

Please come back Brian =(

Jul 24, 2012 at 3:52 PM
Edited Jul 24, 2012 at 3:52 PM

if I do this:

this.extPropertyGrid.SelectedObject = myObj;

foreach (var item in extPropertyGrid.Properties)
{
       // ifs and logic
      { 
            item.Visibility = System.Windows.Visibility.Collapsed;
      }
}

The divisions of categories continue to appear, how to hide them too?

Aug 17, 2012 at 10:10 PM

If your properies "X, Y, Z" are only defined on the "B" type, adding them the "Browsable" attribute to false would probably do the job:

[Browsable(false)]

 

Aug 20, 2012 at 4:44 PM

If I use this tag my property will always be hidden and I want to be able to show and hide them based on the logic of my system.

Aug 21, 2012 at 12:03 AM

Hello,

1. In your xaml, set AutoGenerateProperties="False" for your PropertyGrid.

2. In the PropertyGrid class, look for the private List<PropertyItem> GetObjectProperties method. Inside that method you can put your custom logic to determine which properties will be displayed in the PropertyGrid. The GetObjectProperties method is called every time the selected object changes.

 

Aug 21, 2012 at 10:09 AM
j2associates wrote:

Hello,

1. In your xaml, set AutoGenerateProperties="False" for your PropertyGrid.

2. In the PropertyGrid class, look for the private List<PropertyItem> GetObjectProperties method. Inside that method you can put your custom logic to determine which properties will be displayed in the PropertyGrid. The GetObjectProperties method is called every time the selected object changes.

 

You mean change the code of PropertyGrid.cs? It's not a good idea to change the library code. Actually, propertygrid has a dependency property named "PropertyDefinitions", which can be data binded, but currently it has some bugs, hope it will be fixed in the next release.

Aug 21, 2012 at 12:32 PM

Concerning the PropertyDefinitions bug, you probably refer to this issue:

http://wpftoolkit.codeplex.com/workitem/18301

and yes, it will be fixed in the next version

Aug 22, 2012 at 9:30 AM

Hello,

Obviously changes to the code should be done rarely and carefully, but in cases like this one, that is the only way to accomplish the requirement.

1. We have implemented an ExludedPropertyDefinitions list that exactly mirrors the PropertyDefinitions except in reverse.

2. We have successfully used both PropertyDefinitions and ExcludedPropertyDefinitions in 1.6 code.

3. The best solution would be if the ProperyGrid raised an event (something like CreatingPropertiesList or some such) from the GetObjectProperties method. That way a developer could create their own e.PropertiesList and mark the event handled. This would allow custom property list requirements such as the above without modifying the library code.

Aug 23, 2012 at 1:15 PM

The following issue has been created based on this discussion:

http://wpftoolkit.codeplex.com/workitem/18518