1
我想在窗口上註冊3個依賴項屬性來控制它的格式。我一遍又一遍地查看代碼,但我一定錯過了一些東西。WPF:DependencyProperty拒絕工作
public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register("TextColor", typeof(Color), typeof(WinStickyFingers), new PropertyMetadata(Colors.White));
public Color TextColor {
get { return (Color)base.GetValue(TextColorProperty); }
set { base.SetValue(TextColorProperty, value); }
}
public static readonly DependencyProperty BackgroundColorProperty = DependencyProperty.Register("BackgroundColor", typeof(Color), typeof(WinStickyFingers), new PropertyMetadata(Colors.Black));
public Color BackgroundColor {
get { return (Color)base.GetValue(BackgroundColorProperty); }
set {
base.SetValue(BackgroundColorProperty, value);
}
}
<TextBlock DockPanel.Dock="Top" Text="{Binding Name}" Foreground="{Binding TextColor,Converter={StaticResource DebugConverter}}" Background="{Binding Path=BackgroundColor}" />
我使用Bea Stollnitz的調試方法,但我的斷點甚至沒有觸發。
我的印象是最接近的頂級水平。開發ASP.NET已經污染了我的腦海;) 通過在父容器上設置RelativeSource解決了問題。謝謝。 – Echilon 2009-08-05 14:03:50