2010-01-01 116 views

回答

15

我发现你没有包含一个设计时的DLL来添加一个[类别]属性到自定义控件属性。这是可以完成的一种方式,但事实上,您可以像使用WinForms一样使用任何.NET属性。例如:

/// <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); } 
} 
3

您需要提供一个“元数据程序集”,也称为“设计时间DLL”。这是一个与您的主程序集具有相同名称的程序集,其附加了.Design(例如MyCompany.MyControls.Design.dll),并包含实现IRegisterMetadata的类。 IRegisterMetadata实现为主程序集中的各个组件构建一个属性表,并将其添加到MetadataStore中。

对于完整的信息和示例,请参阅博客文章由苹果酒团队herehere的吉姆·中岛。

有关文档,请参阅MSDN中的WPF Designer Extensibility