在 ComboBox 中设置 FontColor 和 HighlightedItem

Set FontColor and HighlightedItem in ComboBox

我正在尝试确定我的字体颜色和突出显示的颜色。我不知道字体颜色如何,突出显示似乎不起作用。它已经是绑定到组合框的列表。

<ComboBox x:Name="selectCurrentLUT" HorizontalAlignment="Left" 
          Height="21" Margin="2,0,0,0" VerticalAlignment="Top" 
          Width="121" FontSize="15" FontFamily="Microsoft Sans Serif"
          ItemsSource="{Binding AllLUTLibraries}">
    <ComboBox.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="#404040"/>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Yellow" />
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Yellow" />
    </ComboBox.Resources>
</ComboBox>

我在新的 WPF 应用程序中 copied/pasted 你的代码工作正常。

这是一个注释版本,其中包含您想要使用的每个 SolidColorBrush

<ComboBox x:Name="selectCurrentLUT" Width="100" Height="50" FontFamily="Microsoft Sans Serif" ItemsSource="{Binding MyList}">
        <ComboBox.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.WindowTextBrushKey}" Color="Red"/> <!-- Font color of all items -->
            <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Green"/> <!-- Background color of all items -->
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Blue"/> <!-- Font color of the highlighted item -->
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Yellow"/> <!-- Background color of the highlighted item -->
        </ComboBox.Resources>
</ComboBox>

希望对您有所帮助。