希望创建多个条件都为真时才激发的触发器,就需要使用MultiTrigger提供的Condition集合
1 <Window x:Class="Styles.MultiTrigger" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 Title="MultiTrigger" Height="300" Width="300"> 5 <Window.Resources> 6 <Style x:Key="BigFontButton"> 7 <Style.Setters> 8 <Setter Property="Control.FontFamily" 9 Value="Times New Roman" /> 10 <Setter Property="Control.FontSize" 11 Value="18" /> 12 13 </Style.Setters> 14 <Style.Triggers> 15 <MultiTrigger> 16 <MultiTrigger.Conditions> 17 18 <Condition Property="Control.IsFocused" 19 Value="True"></Condition> 20 21 <Condition Property="Control.IsMouseOver" 22 Value="True"></Condition> 23 </MultiTrigger.Conditions> 24 <MultiTrigger.Setters> 25 <Setter Property="Control.Foreground" Value="DarkRed"></Setter> 26 </MultiTrigger.Setters> 27 </MultiTrigger> 28 </Style.Triggers> 29 </Style> 30 </Window.Resources> 31 32 <StackPanel Margin="5"> 33 <Button Padding="5" 34 Margin="5" 35 Style="{StaticResource BigFontButton}">A Customized Button</Button> 36 <TextBlock Margin="5">Normal Content.</TextBlock> 37 <Button Padding="5" 38 Margin="5">A Normal Button</Button> 39 <TextBlock Margin="5">More normal Content.</TextBlock> 40 <Button Padding="5" 41 Margin="5" 42 Style="{StaticResource BigFontButton}">Another Customized Button</Button> 43 </StackPanel> 44 </Window>