views:

140

answers:

1

I'm trying to register 3 dependency properties on a Window to control it's formatting. I've looked over and over the code but I must be missing something.

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}" />

I'm using Bea Stollnitz's debugging method but my breakpoint isn't even triggered.

+1  A: 

What is the DataContext of the TextBlock? How does it know that it is supposed to bind to the properties on your Window?

You need to either set DataContext to the Window instance, or set the Source (or RelativeSource, or ElementName) properties on your bindings. All of these properties exist as a means of resolving the bound object for your Binding. DataContext is a fallback if none of the others is set, but I'm guessing that you haven't set that either.

HTH, Kent

Kent Boogaart
I was under the impression that the closest top level. Developing ASP.NET has polluted my mind ;)Problem solved by setting RelativeSource on the parent container. Thanks.
Echilon