【问题标题】:WPF Toolkit PropertyGrid ExpandableObject attribute doesn't show nested class correctlyWPF Toolkit PropertyGrid ExpandableObject 属性未正确显示嵌套类
【发布时间】:2014-02-07 11:23:44
【问题描述】:

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

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

感谢您的回答!

【问题讨论】:

    标签: c# wpf wpftoolkit propertygrid


    【解决方案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}"/>
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        猜你喜欢
        • 2013-06-05
        • 1970-01-01
        • 2017-04-02
        • 1970-01-01
        • 2019-08-15
        • 2015-01-15
        • 2020-12-22
        • 1970-01-01
        • 2021-06-15
        相关资源
        最近更新 更多