1.1 基本 Trigger
<Window.Resources> <Style TargetType="{x:Type CheckBox}"> <Style.Triggers> <Trigger Property="IsChecked" Value="true"> <Setter Property="Foreground" Value="Orange"></Setter> <Setter Property="FontSize" Value="10"></Setter> </Trigger> </Style.Triggers> </Style> </Window.Resources> <StackPanel> <CheckBox Content="----------------------"></CheckBox> <CheckBox Content="++++++++++++++++++++++"></CheckBox> <CheckBox Content="======================"></CheckBox> <CheckBox Content="______________________"></CheckBox> </StackPanel>
1.2 MultiTrigger
多条件同时满足才会触发
<Window.Resources> <Style TargetType="{x:Type CheckBox}"> <Style.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsChecked" Value="true"></Condition> <Condition Property="Content" Value="小桥流水人家"></Condition> </MultiTrigger.Conditions> <MultiTrigger.Setters> <Setter Property="FontSize" Value="15"></Setter> <Setter Property="Foreground" Value="Red"></Setter> </MultiTrigger.Setters> </MultiTrigger> </Style.Triggers> </Style> </Window.Resources> <StackPanel> <CheckBox Content="枯藤老树昏鸦"></CheckBox> <CheckBox Content="小桥流水人家"></CheckBox> <CheckBox Content="古道西风瘦马"></CheckBox> <CheckBox Content="断肠人在天涯"></CheckBox> </StackPanel>