In WPF, does the order of the triggers matter?

I have the following haml:

<DockPanel> <DockPanel.Resources> <Style TargetType="Button"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="Foreground" Value="Yellow"></Setter> </Trigger> <Trigger Property="IsPressed" Value="True"> <Setter Property="Foreground" Value="Green"></Setter> </Trigger> </Style.Triggers> </Style> </DockPanel.Resources> <Button Content="Cut" Height="30" Width="75"/> </DockPanel> 

What happens when I press a button, the foreground changes to yellow, and then when I press a button, the foreground changes to green.

Now, if I reverse the order of my triggers in XAML, the foreground changes to yellow when I click on it, but when I click on the button, the foreground does not change to green.

What is the explanation for this? Is one trigger a priority for another?

+44
triggers wpf
Feb 18 '09 at 14:09
source share
2 answers

WPF processes triggers in the declared order. In the second example, the foreground is so briefly changed to green. But then the IsMouseOver trigger is launched and returns the color to yellow.

IsMouseOver is not related to IsPressed in terms of priority. Important is the declaration order in XAML triggers.

+57
Feb 18 '09 at 14:12
source share

In short: triggers are processed in order.

Triggers can later undo previous triggers.

+6
Jul 26 '16 at 8:29
source share



All Articles