Search code examples
c#wpfwpftoolkitpropertygridcollectioneditor

How to populate the CollectionControlDialog that comes up when using the PropertyGrid's CollectionEditor (Extended WPF Toolkit)?


Using a PropertyGrid from the Extended WPF Toolkit, I need to use a CollectionEditor:

[Editor(typeof(CollectionEditor), typeof(CollectionEditor))]
public Definition DefTypes { get; set; }

But the CollectionControlDialog that appears when clicking on the DefTypes fields has no items to choose from.

So how do I populate this CollectionControlDialog?


Solution

  • Your CollectionEditor will only show a collection of a certain type of objects. In this case it doesnt look like you are adding the Editor attribute to a collection, but rather to a single object.

    See my code below:

    public class Definition {
        public string SomeProperty { get; set; }
    }
    
    public class Definitions : List<Definition> {
    }
    

    Now you will be able to apply the CollectionEditor to the Definitions:

    [Editor(typeof(CollectionEditor), typeof(CollectionEditor))]
    public Definitions DefTypes { get; set; }
    

    And it will bring up the CollectionEditor with the properties defined in 'Definition'