Search code examples
c#wpfpropertygridxceed

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. 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. Multiple Slide types (classes) could exist that inherits from Slide (main Slide class). 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.

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?

Property Grid Collection Editor

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
   }


}

Solution

  • Seems like I found the answer! Need to use the code below:

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