Sunday, February 28, 2010

Property Grid Editing Support for Collection Type Property - Custom Control

Hi,

Last week I faced some problem while giving property grid editor support for collection type property. For instance my custom control(NavigationControl) inherited from ItemsControl and its item container is NavigationItem. Now when I try to add items through Items property in property grid(In both VS2008 and VS2010), Add button is in disabled state which is present in collection editor dialog box.

To activate this with custom type or collection of types, you can register this in attribute table builder of your designer projects.

For instance,

internal class Metadata : IRegisterMetadata
{

// Called by Cider to register any design-time metadata
public void Register()
{
AttributeTableBuilder builder = new AttributeTableBuilder();
builder.AddCustomAttributes(typeof(NavigationItem), new ToolboxBrowsableAttribute(false));
builder.AddCustomAttributes(typeof(NavigationControl), "Items", new NewItemTypesAttribute(typeof(NavigationItem)));
MetadataStore.AddAttributeTable(builder.CreateTable());
}
}


Thanks,
Venugopal.

No comments:

Post a Comment