我正在使用扩展 WPF 工具包 PropertyGrid 让用户在我的应用程序中填写配置。
一切正常,除非我尝试包含 ExpandableObject 属性以添加嵌套类。
这是一个例子:
public class TestClassConfig
{
public string ExcelName { get; set; }
public string ResultFolder { get; set; }
[ExpandableObject]
public ExpandableTest OtherClass { get; set; }
}
public class ExpandableTest
{
public string Test1 { get; set; }
public string Test2 { get; set; }
}
我无法发布结果的图像(第一篇文章),所以我将对其进行描述:“OtherClass”属性出现但我看不到嵌套类属性(Test1 和 Test2),因此无法对其进行编辑.
在PropertyGrid Documentation ,对于具有 ExpandableObject 属性的属性,它表示 “此属性是一个复杂属性,没有默认编辑器。”
这是否意味着我每次想将嵌套类添加到我的属性网格时都必须创建一个自定义编辑器?
感谢您的回答!
最佳答案
因此,了解如何在 xaml 中绑定(bind)它会非常有用。 我这样做:
public class TestClassConfig
{
[Category("Cat1")]
public string ExcelName { get; set; }
[Category("Cat1")]
public string ResultFolder { get; set; }
[Category("CatWithExpandObj")]
[ExpandableObject]
public ExpandableTest OtherClass { get; set; }
}
public class ExpandableTest
{
public string Test1 { get; set; }
public string Test2 { get; set; }
}
在 xaml 中,您必须绑定(bind) Selected object
:
<xctk:PropertyGrid SelectedObject="{Binding TestClassConfig}"/>
关于c# - WPF 工具包 PropertyGrid ExpandableObject 属性未正确显示嵌套类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21626477/