3,WPF 四大触发器总结 - 图1
    参考:
    https://blog.csdn.net/lhx527099095/article/details/8029207
    例子1 简单触发器Triggers——满足简答的条件,触发

    1. <Window x:Class="Styles.SimpleTriggers"
    2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    4. Title="SimpleTriggers" Height="300" Width="300"
    5. >
    6. <Window.Resources>
    7. <Style x:Key="BigFontButton">
    8. <Style.Setters>
    9. <Setter Property="Control.FontFamily" Value="Times New Roman" />
    10. <Setter Property="Control.FontSize" Value="10" />
    11. </Style.Setters>
    12. <Style.Triggers>
    13. <Trigger Property="Control.IsFocused" Value="True">
    14. <Setter Property="Control.Foreground" Value="DarkRed" />
    15. </Trigger>
    16. <!--<Trigger Property="Control.IsMouseOver" Value="True">
    17. <Setter Property="Control.Foreground" Value="LightYellow" />
    18. <Setter Property="Control.FontWeight" Value="Bold" />
    19. </Trigger>
    20. <Trigger Property="Button.IsPressed" Value="True">
    21. <Setter Property="Control.Foreground" Value="Red" />
    22. </Trigger>-->
    23. </Style.Triggers>
    24. </Style>
    25. </Window.Resources>
    26. <StackPanel Margin="5">
    27. <Button Padding="5" Margin="5"
    28. Style="{StaticResource BigFontButton}"
    29. >A Customized Button</Button>
    30. <TextBlock Margin="5">Normal Content.</TextBlock>
    31. <Button Padding="5" Margin="5"
    32. >A Normal Button</Button>
    33. <TextBlock Margin="5">More normal Content.</TextBlock>
    34. <Button Padding="5" Margin="5"
    35. Style="{StaticResource BigFontButton}"
    36. >Another Customized Button</Button>
    37. </StackPanel>
    38. </Window>

    例子2 条件多触发MultiTriggers——满足多条件才触发








    例子3 事件触发器EventTrigger——在特定的路由事件发生时被触发,主要用于动画。

    例字4 数据触发器DataTrigger——根据绑定的数据不同显示不同的内容。



    Background=”Transparent” DataContext=”{Binding}” PreviewMouseMove=”TreeItem_PreviewMouseMove”>

    3,WPF 四大触发器总结 - 图2