如何創建簡單布爾依賴項屬性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