wpf - 在 ComboBoxItem 中设置文本颜色

标签 wpf xaml colors combobox

我想为 PASS 设置文本颜色如 GREENFAIL 的文本颜色如 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>

关于wpf - 在 ComboBoxItem 中设置文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18478778/

相关文章:

colors - Windows CMD 改变一个字符的颜色

c# - 具有连续滚动功能的 Leadtools PDF 查看器

wpf - WPF中的可点击ItemsControl项

c# - XAML 中的按钮不可单击

c# - 找不到资源WPF工具包

javascript - 创建 jsFiddle/jsbin.com 样式代码编辑器的工具?

android - 半透明白色位图显示为不透明白色

c# - 代码优化: Create a method for recurring procedures

c# - 如何为您的 WPF 应用程序提供平面 (Windows 8) 类型的 UI 外观?

wpf - 代码和 XAMLin WPF 之间的界线在哪里?