Visual Studio 2010设计时集合编辑器

5

我正在为WPF和Silverlight开发一个自定义控件。该控件具有一个复杂类型的集合属性,该类型是抽象的,例如:

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>()));

我的问题是,我无法在Visual Studio 2010的设计器中添加新项,因为它不知道MyBase的任何派生类型。
有没有办法向设计器注册这些类型?编辑器可以正常使用现有项目,并且可以删除和修改它们。以下是一张图片以进行说明:
1个回答

5

您需要使用NewItemTypesAttribute来装饰您的集合属性。您可以直接在类中这样做,但在WPF / Silverlight中,这些通常在单独的设计程序集中定义。这里有一个很好的步骤说明:这里


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接