是否可以将其减少为单个触发器?
<Style x:Key="StatusTextBlock" TargetType="{x:Type TextBlock}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Text,
RelativeSource={RelativeSource Self}}" Value="Running">
<Setter Property="Foreground" Value="Green"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Text,
RelativeSource={RelativeSource Self}}" Value="Paused">
<Setter Property="Foreground" Value="Yellow"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding Path=Text,
RelativeSource={RelativeSource Self}}" Value="Stopped">
<Setter Property="Foreground" Value="Red"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
答案 0 :(得分:0)
如果"Running"
和"Stopped"
是唯一两个可用案例,您可以将其中一个设置为属性,并且只使用一个触发器:
<Style x:Key="StatusTextBlock" TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Green" /> <!--default case == Running -->
<Style.Triggers>
<DataTrigger Binding="{Binding Path=Text,
RelativeSource={RelativeSource Self}}" Value="Stopped">
<Setter Property="Foreground" Value="Red"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>