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:
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With