简体   繁体   English

Xceed WPF Propertygrid-集合控件:多种类型

[英]Xceed WPF Propertygrid - Collection Control: Multiple Types

I'm using the Xceed WPF Property Grid control to edit properties of objects and collections of objects. 我正在使用Xceed WPF属性网格控件来编辑对象的属性和对象的集合。 I noticed that the collection editor has the option of selecting a type, as seen in the image below. 我注意到集合编辑器可以选择类型,如下图所示。 How would I go about adding multiple types that inherits from a base class? 如何添加从基类继承的多个类型?

For example, I have a class Presentation which have a list of Slides. 例如,我有一个Presentation类,其中包含一张幻灯片列表。 Multiple Slide types (classes) could exist that inherits from Slide (main Slide class). 可以存在从Slide(主Slide类)继承的多个Slide类型(类)。 See code below. 请参见下面的代码。 The idea is to link the Property Grid to the Presentation object (Presentation class), and when the Slides collection is edited, the Collection Editor will have all the slide types available which can be selected via the "Select Type" combo box. 想法是将属性网格链接到Presentation对象(Presentation类),并且在编辑Slides集合时,集合编辑器将具有所有可用的幻灯片类型,可以通过“选择类型”组合框进行选择。

This will enable the user to seamlessly add different slide types that is stored in one collection object (List). 这将使用户能够无缝地添加存储在一个集合对象(列表)中的不同幻灯片类型。

Any idea how I can make this work? 知道如何使这项工作有效吗?

属性网格集合编辑器

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
   }


}

Seems like I found the answer! 好像我找到了答案! Need to use the code below: 需要使用下面的代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM