5

I am working on a custom control for WPF and Silverlight. This control has a collection property of a complex type that is abstract, like such:

public Collection<MyBase> Configuration
    {
        get { return (Collection<MyBase>)GetValue(ConfigurationProperty); }
        set { SetValue(ConfigurationProperty, value); }
    }

    // Using a DependencyProperty as the backing store for Configuration This enables animation, styling, binding, etc...
    public static readonly DependencyProperty ConfigurationProperty =
        DependencyProperty.Register("Configuration", typeof(Collection<MyBase>), typeof(MyControl), new PropertyMetadata(new ObservableCollection<MyBase>()));

My problem is that I can't add new items to this property in Visual Studio 2010's designer because it doesnt know any derived types of MyBase.

Is there any way to register these types with the designer? The editor works fine with existing items, and can remove and modify them. An image to illustrate:

enter image description here

Bas
  • 26,772
  • 8
  • 53
  • 86

1 Answers1

5

You would need to decorate your collection property with the NewItemTypesAttribute. You can do this directly in your class, but in WPF/Silverlight these are generally defined in a separate design assembly. There is a good walk through of this here.

CodeNaked
  • 40,753
  • 6
  • 122
  • 148