[英]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. 我尝试使用PropertyGrid(实际上,它是xceed wpf工具包的propertygrid,但是如果可以简化,我可以切换到标准形式的PropertyGrid),并且我需要在网格中显示的对象具有一些我需要的子对象才能扩展。
I found out I can achieve this by marking the properties with the "ExpandableObject" attribute. 我发现可以通过使用“ ExpandableObject”属性标记属性来实现此目的。 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. 但是,在某些情况下,我不是该类的作者(或者我是该类的作者,但不想将其与GUI-stuff混淆),因此无法添加此类属性。
Is there any other way to tell the PropertyGrid which properties that should be expandable? 还有其他方法可以告诉PropertyGrid哪些属性应该可扩展?
Xceed property grid has an event PreparePropertyItem
. Xceed属性网格具有一个事件PreparePropertyItem
。 You can handle it and set e.PropertyItem.IsExpandable
property. 您可以处理它并设置e.PropertyItem.IsExpandable
属性。 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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.