WPF TextBlock 根据Text值,改变字体颜色
作者:互联网
<TextBlock x:Name="labelState" Text="{Binding SourcePowerState}" Grid.Row="1" Grid.Column="3" VerticalAlignment="Center" Width="50" FontSize="20">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Setter Property="Foreground" Value="Green"></Setter>
<Style.Triggers>
<Trigger Property="Text" Value="异常">
<Setter Property="Foreground" Value="Red"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
Text 绑定 SourcePowerState,
如果是异常, 字体颜色是红色
如果是正常, 字体颜色是绿色
标签:颜色,SourcePowerState,TextBlock,字体,Text,WPF 来源: https://blog.csdn.net/orangapple/article/details/119085483