WPF:受抚养人财产拒绝工作

WPF:受抚养人财产拒绝工作,wpf,data-binding,dependency-properties,Wpf,Data Binding,Dependency Properties,我试图在一个窗口上注册3个依赖属性来控制它的格式。我看了一遍又一遍代码,但一定是遗漏了什么 public static readonly DependencyProperty TextColorProperty = DependencyProperty.Register("TextColor", typeof(Color), typeof(WinStickyFingers), new PropertyMetadata(Colors.White)); public Color TextColor

我试图在一个窗口上注册3个依赖属性来控制它的格式。我看了一遍又一遍代码,但一定是遗漏了什么

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}" />
public static readonly dependencProperty TextColorProperty=dependencProperty.Register(“TextColor”、typeof(Color)、typeof(WinStickyFingers)、new PropertyMetadata(Colors.White));
公共颜色文本颜色{
获取{return(Color)base.GetValue(TextColorProperty);}
set{base.SetValue(TextColorProperty,value);}
}
public static readonly dependencProperty BackgroundColorProperty=dependencProperty.Register(“BackgroundColor”、typeof(Color)、typeof(WinStickyFingers)、new PropertyMetadata(Colors.Black));
公共色背景色{
获取{return(Color)base.GetValue(BackgroundColorProperty);}
设置{
base.SetValue(BackgroundColorProperty,value);
}
}    

我正在使用Bea Stollnitz的调试方法,但我的断点甚至没有被触发

文本块的
DataContext
是什么?它如何知道应该绑定到
窗口上的属性


您需要将
DataContext
设置到
窗口
实例,或在绑定上设置
(或
相对源
,或
元素名
)属性。所有这些属性都是解析
绑定的绑定对象的一种方法<如果没有设置任何其他设置,则code>DataContext
是一种回退,但我猜您也没有设置。

文本块的
DataContext
是什么?它如何知道应该绑定到
窗口上的属性


您需要将
DataContext
设置到
窗口
实例,或在绑定上设置
(或
相对源
,或
元素名
)属性。所有这些属性都是解析
绑定的绑定对象的一种方法
DataContext
是一个后备方案,如果其他方案都没有设置,但我猜您也没有设置。

我的印象是,最接近的顶层。开发ASP.NET污染了我的思想;)通过在父容器上设置RelativeSource解决了此问题。谢谢。我的印象是最接近顶级的。开发ASP.NET污染了我的思想;)通过在父容器上设置RelativeSource解决了此问题。谢谢