I'm trying to create a WPF UserControl which contains 2 buttons. I use this UserControl in a Window and apply a Window.Resource value to set the background of one button inside the user control.
Currently I have:
window.xaml
<Window.Resources> <SolidColorBrush Color="Brown" x:Key="theBG"></SolidColorBrush> </Window.Resources> <theControl:TheControl x:Name="TheControl" buttonBG="{Binding Source={StaticResource theBG}}" />
usercontrol.xaml.cs
public SolidColorBrush buttonBG { get { return base.GetValue(buttonBGProperty) as SolidColorBrush; } set { base.SetValue(buttonBGProperty, value); } } public static readonly DependencyProperty buttonBGProperty = DependencyProperty.Register("buttonBG", typeof(SolidColorBrush), typeof(DataPanel), null);
usercontrol.xaml
<Button ... Background="{Binding buttonBG}">
I was expecting this to work but the background is not the one I set in the window resource.
What am I doing wrong?