[英]PropertyGrid - Specify ExpandableObject if I don't have control of the class
[英]WPF Toolkit PropertyGrid ExpandableObject attribute doesn't show nested class correctly
我正在使用擴展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文檔中 ,它對具有ExpandableObject屬性的屬性說: “此屬性是一個復雜的屬性,沒有默認編輯器。”
這是否意味着我每次想向屬性網格中添加嵌套類時都必須創建一個自定義編輯器?
感謝您的回答!
因此,了解如何將其綁定到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}"/>
我知道這是一個較晚的答案,但是,請確保該屬性的值不為null。 換句話說,編寫如下內容:
public class TestClassConfig
{
[Category("CatWithExpandObj")]
[ExpandableObject]
public ExpandableTest OtherClass { get; set; } = new ExpandableTest();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.