简体   繁体   English

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

[英]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.

相关问题 WPF工具包PropertyGrid ExpandableObject属性不能正确显示嵌套类 - WPF Toolkit PropertyGrid ExpandableObject attribute doesn't show nested class correctly 有没有一种方法可以设置类中字段的默认值,从而不必在创建时指定值? - Is there a way that I can set the default values of fields in a class so I don't have to specify a value on creation? BinaryEditor 类不适用于 .net 6 预览中的 PropertyGrid 控件 - BinaryEditor class doesn't work for PropertyGrid control in .net 6 preview 如何将属性注入到我无法控制其创建的类中 - How to inject a property into a class that I don't control the creation of 验证您无法控制数据或类的类的属性? - Validating properties of a class where you don't have control of the data or the class? 无法在PropertyGrid中显示具有接口属性的类 - Can't show class with interface properties in PropertyGrid 为什么在Visual Studio 2013 Express中,我没有项目模板Windows Control Library? - Why in visual studio 2013 express, I don't have a project template Windows Control Library? 如果我的课程中没有相应的具有该名称的属性,我应该提高INotifyPropertyChanged事件吗? - Should I raise INotifyPropertyChanged events if I don't have a corresponding property with that name on my class? 如何将不隐藏控件的自定义 Visible 属性添加到 PropertyGrid? - How to add custom Visible property that doesn't hide the control to PropertyGrid? 我在将一个类引用到另一个类时遇到了一些问题,我得到的错误是我没有关于正式周界的论据 - I'm having some issues referencing a class to another class and the error I'm getting is I don't have an argument for a formal perimeter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM