Hi.
I have a very simple UserControl as shown below. I'm trying to get the background of the Label element to change whenever a property in the control changes, but it's not working: when I change the Selected property on the control instance, the label's background color does not change.
Thanks!
Code behind:
public static readonly DependencyProperty SelectedProperty =
DependencyProperty.Register("Selected",
typeof(bool),
typeof(UICatcherContactlistItem),
new FrameworkPropertyMetadata((bool)false));
public bool Selected
{
get { return (bool)GetValue(SelectedProperty); }
set { SetValue(SelectedProperty, value); }
}
Xaml:
<UserControl x:Class="UICatcherContactlistItem" [....]>
<Label Name="name" Foreground="#888888">
<Style TargetType="{x:Type Label}">
<Style.Triggers>
<DataTrigger Binding="{Binding Selected}" Value="True">
<Setter Property="Background" Value="Red"/>
</DataTrigger>
<DataTrigger Binding="{Binding Selected}" Value="False">
<Setter Property="Background" Value="Blue"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Label>
</UserControl>