PropertyGrid expanded/collapsed categories

Grids for WPF Forum

Posted 3 years ago by Procam
Version: 20.1.0
Avatar

Hello,

is there a way how to preserve the collapsed/exttended categories in PropertyGrid?

For example:

I have a class MyClass with properties A, B, C and D:

- Properties A and B have attribute [Category("Info")]

- Property C has attribute [Category("General")]

- Property D has attribute [Category("Misc")]

Is there a way how to display at first loading (until user manually changes it) the category "Info" as expanded?

What I need is to have all categories collapsed, and only the "Info" to be expanded.

Thanks!

Comments (2)

Posted 3 years ago by Procam
Avatar

Just, the answer to my question :)

private void OnCustomPropertyGridRootItemChanged(object sender, System.Windows.RoutedEventArgs e)
{
    if (!(e.OriginalSource is CustomPropertyGrid)) return;
 
    System.Collections.ICollection items = ((CustomPropertyGrid)e.OriginalSource).Items;
    object[] array = new object[items.Count];
    items.CopyTo(array, 0);
    for (int i = 0; i < array.Length; i++)
    {
        if (!(array[i] is ICategoryModel cat)) continue;
 
        cat.IsExpanded = cat.Name == "Info";
    }
}

[Modified 3 years ago]

Posted 3 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Another way would be to make a class that inherits TypeDescriptorFactory and override the GetDataModels method to call its base method, examine the results, and expand ICategoryModels as appropriate.  


Actipro Software Support

The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.