c# - WPF 工具包 PropertyGrid ExpandableObject 属性未正确显示嵌套类

标签 c# wpf wpftoolkit propertygrid

我正在使用扩展 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/

相关文章:

c# - JavaScriptSerializer [ScriptIgnore] 对虚拟属性无效?

c# - 如何给表格上色 逐渐从黄色到绿色

WPF Animate 双属性更改

c# - WPF 捕捉控件

wpf - 是否可以在 WPF 中使用 "stylesheet"?

c# - 需要多个相似字符串的正则表达式

c# - FormsAuthenticationTicket 不能在服务器端失效。引起 cookie 回复攻击

wpf - WPF:不带下拉按钮的组合框

c# - 样式化 Wpf 饼图

wpf - 线程和 WPF 的绑定(bind)