Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# PropertyGrid-如果我没有';我不能控制这个班_C#_Wpf_Propertygrid - Fatal编程技术网

C# PropertyGrid-如果我没有';我不能控制这个班

C# PropertyGrid-如果我没有';我不能控制这个班,c#,wpf,propertygrid,C#,Wpf,Propertygrid,我尝试使用PropertyGrid(实际上,它是xceed wpf toolkit PropertyGrid,但如果这样做更容易的话,我可以切换到标准表单PropertyGrid),我需要在网格中显示的对象有一些子对象,我需要能够扩展 我发现我可以通过使用“ExpandableObject”属性标记属性来实现这一点。但是,在某些情况下,我不是这个类的作者(或者我是,但不想用GUI的东西把它弄得乱七八糟),所以我不能添加这样的属性 是否有其他方法告诉PropertyGrid哪些属性应该可扩展?Xc

我尝试使用PropertyGrid(实际上,它是xceed wpf toolkit PropertyGrid,但如果这样做更容易的话,我可以切换到标准表单PropertyGrid),我需要在网格中显示的对象有一些子对象,我需要能够扩展

我发现我可以通过使用“ExpandableObject”属性标记属性来实现这一点。但是,在某些情况下,我不是这个类的作者(或者我是,但不想用GUI的东西把它弄得乱七八糟),所以我不能添加这样的属性


是否有其他方法告诉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;
    }
}
也许您可以使用一个公开装饰对象的所有属性,但标记为“ExpandableObject”属性