Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 design time collection editor

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

like image 511
Bas Avatar asked Apr 08 '11 16:04

Bas


People also ask

Can't see Windows Form Designer?

We need to enable the designer in Visual Studio. Go to Tools > Options > Environment > Preview Features and select the Use the preview Windows Forms designer for . NET Core apps option.

How do I get the properties tab in Visual Studio?

You can find Properties Window on the View menu. You can also open it by pressing F4 or by typing Properties in the search box.


1 Answers

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.

like image 117
CodeNaked Avatar answered Sep 23 '22 11:09

CodeNaked