Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set property category for WPF custom control?

In WinForms, I could add a [Category] attribute to a custom control property to specify which property category should contain the property. How do I do that in WPF? Thanks

like image 213
David Veeneman Avatar asked Jan 01 '10 18:01

David Veeneman


2 Answers

I have discovered that you don't have to include a design-time DLL to add a [Category] attribute to a custom control property. That is one way that it can be done, but in fact, you can use any .NET attribute just as you did in WinForms. For example:

/// <summary>
/// The image displayed by the button.
/// </summary>
/// <remarks>The image is specified in XAML as an absolute or relative path.</remarks>
[Description("The image displayed by the button."), Category("Common Properties")] 
public ImageSource Image
{
    get { return (ImageSource)GetValue(ImageProperty); }
    set { SetValue(ImageProperty, value); }
}
like image 100
David Veeneman Avatar answered Oct 02 '22 07:10

David Veeneman


You need to provide a "metadata assembly," also known as a "design time DLL." This is an assembly with the same name as your main assembly with .Design appended to it (e.g. MyCompany.MyControls.Design.dll), and containing a class that implements IRegisterMetadata. The IRegisterMetadata implementation builds a table of attributes for the various components in your main assembly, and adds this to a MetadataStore.

For full info and examples, see blog posts by Jim Nakashima of the Cider team here and here.

For documentation, see WPF Designer Extensibility in MSDN.

like image 39
itowlson Avatar answered Oct 02 '22 06:10

itowlson