繁体   English   中英

PropertyGrid-如果我无法控制该类,请指定ExpandableObject

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

我尝试使用PropertyGrid(实际上,它是xceed wpf工具包的propertygrid,但是如果可以简化,我可以切换到标准形式的PropertyGrid),并且我需要在网格中显示的对象具有一些我需要的子对象才能扩展。

我发现可以通过使用“ ExpandableObject”属性标记属性来实现此目的。 但是,在某些情况下,我不是该类的作者(或者我是该类的作者,但不想将其与GUI-stuff混淆),因此无法添加此类属性。

还有其他方法可以告诉PropertyGrid哪些属性应该可扩展?

Xceed属性网格具有一个事件PreparePropertyItem 您可以处理它并设置e.PropertyItem.IsExpandable属性。 有一个使所有非基本属性都可扩展的处理程序示例:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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