Articles in this section
Category / Section

How to expand all nested level properties in WPF PropertyGrid?

1 min read

We can expand and collapse a nested level property in propertygrid by using the “StatusChanged” event, by setting the “IsChecked” property to “True” for the ToggleButton. The same has been demonstrated in the following sample.

 

Code Example [C#]:

 
private void PropertyGrid_Loaded(object sender, RoutedEventArgs e)
{
    PropertyView item1 = VisualUtils.FindDescendant(this, typeof(PropertyView)) as PropertyView;
 
    if (item1 != null)
       item1.ItemContainerGenerator.StatusChanged += ItemContainerGenerator_StatusChanged;
}
 
void ItemContainerGenerator_StatusChanged(object sender, EventArgs e)
{
    foreach (PropertyCatagoryViewItem item in VisualUtils.EnumChildrenOfType(this, typeof(PropertyCatagoryViewItem)))
     {
      foreach (var items in item.Items)
          {
            foreach (PropertyViewItem propertyviewitem in VisualUtils.EnumChildrenOfType(this, typeof(PropertyViewItem)))
                {
                  ToggleButton button = (ToggleButton)propertyviewitem.Template.FindName("ToggleButton", propertyviewitem);
                   if (button.Visibility == System.Windows.Visibility.Visible && !button.IsMouseOver)
                      {
                        button.IsChecked = true;
                      }
                 }
          }
     }
}
 

 

 

 

 

 

 

 

 

Output:

ExpandNestedLevelProperty

 

 

Sample Link: PropertyGrid

 


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please  to leave a comment
Access denied
Access denied