简体   繁体   中英

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?

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM