【问题标题】:Xceed WPF Propertygrid - Collection Control: Multiple TypesXceed WPF Propertygrid - 集合控件:多种类型
【发布时间】:2017-07-13 07:40:37
【问题描述】:

我正在使用 Xceed WPF 属性网格控件来编辑对象的属性和对象的集合。我注意到集合编辑器可以选择类型,如下图所示。我将如何添加从基类继承的多种类型?

例如,我有一个具有幻灯片列表的类 Presentation。可以存在多个从 Slide(主 Slide 类)继承的 Slide 类型(类)。请参阅下面的代码。想法是将 Property Grid 链接到 Presentation 对象(Presentation 类),当编辑 Slides 集合时,集合编辑器将拥有所有可用的幻灯片类型,可以通过“选择类型”组合框进行选择。

这将使用户能够无缝地添加存储在一个集合对象(列表)中的不同幻灯片类型。

知道我该如何完成这项工作吗?

public class Presentation
{
     private List<Slide> _slides = new List<Slide>();
     [DisplayName("Slides List")]
     [Description("Slides List")]
     [Category("Presentation Content")]
     [PropertyOrder(1)]
     public List<Slides> slides
     {
         get
         {
             return (_slides );
         }
         set
         {
             _slides = value;
         }
     }

   public class Slide
   {

      //Properties of slide

   }

   public class SlideType1: Slide
   {

      //Properties of slide type 1
   }

   public class SlideType2: Slide
   {

      //Properties of slide type 2
   }


}

【问题讨论】:

    标签: c# wpf propertygrid xceed


    【解决方案1】:

    好像我找到了答案!需要使用下面的代码:

    [NewItemTypes(typeof(Slide1), typeof(Slide2))]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多