WPF Toolkit PropertyGrid ExpandableObject属性未正确显示嵌套类

时间:2014-02-07 11:23:45

标签: c# wpf wpftoolkit propertygrid

我正在使用Extended 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属性的属性“此属性是一个复杂属性,没有默认编辑器。”

这是否意味着我每次要将嵌套类添加到属性网格时都必须创建自定义编辑器?

感谢您的回答!

2 个答案:

答案 0 :(得分:1)

因此,知道如何在xaml中绑定它会非常有用。 我是这样做的:

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中你绑定Selected object

<xctk:PropertyGrid SelectedObject="{Binding TestClassConfig}"/>

答案 1 :(得分:0)

我知道这是一个迟到的答案,但请确保该属性的值不为null。换句话说,写下这样的东西:

public class TestClassConfig
{
  [Category("CatWithExpandObj")]
  [ExpandableObject]
   public ExpandableTest OtherClass { get; set; } = new ExpandableTest();
}
相关问题