Visual Studio 2010设计时集合编辑器

Bas*_*Bas 5 .net c# design-time visual-studio-2010

我正在为WPF和Silverlight开发自定义控件.此控件具有抽象的复杂类型的collection属性,如下所示:

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>()));
Run Code Online (Sandbox Code Playgroud)

我的问题是我无法在Visual Studio 2010的设计器中向此属性添加新项目,因为它不知道任何派生类型的MyBase.

有没有办法向设计师注册这些类型?编辑器可以正常使用现有项目,并可以删除和修改它们.一张图片来说明:

在此输入图像描述

Cod*_*ked 5

您需要使用NewItemTypesAttribute修饰集合属性.您可以直接在您的类中执行此操作,但在WPF/Silverlight中,这些通常在单独的设计程序集中定义.还有就是通过这个好走这里.