如何创建简单布尔依赖项属性IsInput
。当在代码中创建类时,此值只能设置为true
或false
。看起来很简单,但是在网上搜索并没有找到明确的例子。WPF布尔依赖项属性C#
我在网上看到过这样一个例子,但我不清楚我会重复什么来正确创建我自己的布尔依赖属性。
public static readonly DependencyProperty AncestorProperty =
DependencyProperty.Register("Ancestor", typeof(FrameworkElement), typeof(MyItem),
new FrameworkPropertyMetadata(Ancestor_PropertyChanged));
/// <summary>
/// Event raised when 'Ancestor' property has changed.
/// </summary>
private static void Ancestor_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MyItem c = (MyItem)d;
c.UpdateHotspot();
}
只要阅读文档https://msdn.microsoft.com/en-us/library/ms752914(v=vs.100).aspx – chameleon86