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? Tha开发者_运维技巧nks
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); }
}
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.
精彩评论