DataTrigger does not shoot

I have the following haml:

<DockPanel> <DockPanel> <CheckBox IsChecked="{Binding Path=Test}" /> <CheckBox IsChecked="{Binding Path=Test}" /> </DockPanel> <DockPanel DockPanel.Dock="Left" Width="10" Background="Blue"> <DockPanel.Style> <Style> <Style.Triggers> <DataTrigger Binding="{Binding Path=Test}" Value="True"> <Setter Property="DockPanel.Background" Value="Yellow" /> </DataTrigger> </Style.Triggers> </Style> </DockPanel.Style> </DockPanel> </DockPanel> 

Now - 2 flags are correctly connected - the check will be the check of another - but the datatrigger does not shoot at all.

What am I doing wrong?

+6
wpf xaml datatrigger
source share
1 answer

The problem here is the priority of the property value .

You are currently setting Background to blue directly on the DockPanel. This explicit property will override any value specified by the trigger.

Instead, you should set the original Background as a setter in style.

  <DockPanel DockPanel.Dock="Left" Width="10"> <DockPanel.Style> <Style> <Setter Property="DockPanel.Background" Value="Blue" /> <Style.Triggers> <DataTrigger Binding="{Binding Path=Test}" Value="True"> <Setter Property="DockPanel.Background" Value="Yellow" /> </DataTrigger> </Style.Triggers> </Style> </DockPanel.Style> </DockPanel></DockPanel> 
+18
source share

All Articles