我希望能够用自定义属性来标记任何控件,例如像“Obsolete”一样。
另外一个要求是,我希望微软的Visual Studio和Blend忽略这个属性!
我注意到Blend使用mc:Ignorable="d"
并添加d:DesignerWidth
属性。
我应该如何用自定义属性来标记我的控件?我需要确保如果dll丢失,Visual Studio和Blend将忽略此属性。
我希望能够用自定义属性来标记任何控件,例如像“Obsolete”一样。
另外一个要求是,我希望微软的Visual Studio和Blend忽略这个属性!
我注意到Blend使用mc:Ignorable="d"
并添加d:DesignerWidth
属性。
我应该如何用自定义属性来标记我的控件?我需要确保如果dll丢失,Visual Studio和Blend将忽略此属性。
您的请求的第一部分可以通过使用依赖属性或附加属性来完成。
请参考以下示例代码:
public static readonly DependencyProperty ObsoleteAttached = DependencyProperty.RegisterAttached(
"ObsoleteAttached", typeof(Boolean), typeof(UserControl1), new UIPropertyMetadata(false)
);
public static Boolean GetObsoleteAttached(DependencyObject obj)
{
return (Boolean)obj.GetValue(ObsoleteAttached);
}
public static void SetObsoleteAttached(DependencyObject obj, Boolean value)
{
obj.SetValue(ObsoleteAttached, value);
}
public Boolean Obsolete
{
get { return (Boolean)this.GetValue(ObsoleteProperty); }
set
{
this.SetValue(ObsoleteProperty, value);
}
}
public static readonly DependencyProperty ObsoleteProperty = DependencyProperty.Register(
"Obsolete", typeof(Boolean), typeof(UserControl1), new PropertyMetadata(false));
你的第二部分需要更多的澄清,比如为什么你想让Visual Studio或Blend忽略这个属性?此外,你所说的“如果dll丢失,visual studio和blend将忽略这个属性”是什么意思?为了改进这个答案,我需要从你那里得到更多的细节,否则它仍然主要是猜测。
你可以在这里下载完整的源代码。该应用程序允许你选择不同的图像资源,但它是为了演示“请求”的目的而制作的。
更多参考资料: