Henrik Berg
Henrik Berg

Reputation: 549

PropertyGrid - Specify ExpandableObject if I don't have control of the class

I try to use a PropertyGrid (actually, it's the xceed wpf toolkit propertygrid, but I can switch to the standard forms PropertyGrid if that makes it easier), and the object I need to show in the grid has some child-objects that I need to be able to expand.

I found out I can achieve this by marking the properties with the "ExpandableObject" attribute. However, in some cases I am not the author of the class (or I am, but don't want to clutter it with GUI-stuff), so I cannot add attributes like that.

Is there any other way to tell the PropertyGrid which properties that should be expandable?

Upvotes: 1

Views: 1219

Answers (1)

igorushi
igorushi

Reputation: 1995

Xceed property grid has an event PreparePropertyItem. You can handle it and set e.PropertyItem.IsExpandable property. There is an example of handler that makes all non primitive properties expandable:

private void propertyGrid_PreparePropertyItem(object sender, Xceed.Wpf.Toolkit.PropertyGrid.PropertyItemEventArgs e)
{
    var item = e.Item as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
    if (item == null)
        return;
    if (!item.PropertyType.IsValueType && item.PropertyType != typeof(string))
    {
        e.PropertyItem.IsExpandable = true;
    }
}

Upvotes: 3

Related Questions