[英]Setting text color in ComboBoxItem
我想将PASS
的文本颜色设置为GREEN
,将FAIL
的文本颜色设置为RED
。 我似乎找不到解决方案。 我需要在纯XAML中执行此操作。
<ComboBox x:Name="LocatedCorrectly" Width="100"
Height="25" Grid.Column="1" Grid.Row="2"
HorizontalAlignment="Left"
IsSynchronizedWithCurrentItem="True">
<ComboBoxItem Content="PASS" Tag="PASS" IsSelected="True"/>
<ComboBoxItem Content="FAIL" Tag="FAILED" />
</ComboBox>
您可以对它使用触发器(您也应该继承基本样式)
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Foreground" Value="Blue" />
<Style.Triggers>
<Trigger Property="Content" Value="PASS">
<Setter Property="Foreground" Value="Green"/>
</Trigger>
</Style.Triggers>
</Style>
我建议通过在Window.Resources中单独创建样式文档,然后对ComboBox项进行样式设置以具有所需的任何前景色来更改样式。
<ComboBox.Resources>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Foreground" Value="Blue" />
</Style>
</ComboBox.Resources>
如果要将其保留在Application.Resources中,那么我认为您需要跟踪用于设置TextBlock.Text颜色的x:Static笔刷键并将其覆盖在ComboBox.Resources中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.