WPF触发器与动画详解
1. 使用DataTrigger
1.1 DataTrigger简介
Style除了在ControlTemplate中拥有Triggers集合外,自身也有Triggers集合。如果触发器仅用于响应和更改控件的属性,而非ControlTemplate内元素的属性,那么可以使用Style的Triggers集合。
1.2 示例:修复静音按钮
下面通过一个示例来展示如何使用DataTrigger修复静音按钮:
1. 打开MediaPlayer.xaml文件,找到用于静音的ToggleButton。
2. 将按钮的内容替换为以下XAML代码:
<Grid> <Canvas Width="20" Height="20"> <!-- the speaker --> <Path Fill="{StaticResource redRadial}" Stroke="{StaticResource controlOutline}" StrokeLineJoin="Round"> <Path.Data> <PathGeometry> <PathFigure StartPoint="12,5" IsClose