Technology Researcher
Technology Researcher

Reputation: 553

WPF comboboxitem foreground color change

I'm trying to change the color of the comboboxitem in wpf, but for some reason it doesn't change and I don't know why. The items do get loaded I can tell and verify that but i don't see them there not white or black but the same color as the background of the combobox which is kinda gray.

This is what i have to change the comboboxitem color foregournd to black, but does not work.

<ComboBox Foreground="#FF000000" x:Name="cBox_nosave" Width="149.8192" Height="22" Canvas.Left="23.7296000000033" Canvas.Top="40.7904000000016">
    <ComboBox.ItemTemplate>
      <DataTemplate>
        <TextBlock Grid.Column="1" Margin="2, 1" Text="{Binding Name}" />
      </DataTemplate>
    </ComboBox.ItemTemplate>
    <ComboBox.ItemContainerStyle>
      <Style TargetType="{x:Type ComboBoxItem}">
        <Setter Property="Foreground" Value="Black" />
      </Style>
    </ComboBox.ItemContainerStyle>
  </ComboBox>

What do I need to do to change the foreground color to black? working in wpf .net version 4.6.1

Upvotes: 0

Views: 1108

Answers (1)

user13305916
user13305916

Reputation:

Try to set TextBlock foreground in item template

<ComboBox Foreground="#FF000000" x:Name="cBox_nosave" Width="149.8192" Height="22" Canvas.Left="23.7296000000033" Canvas.Top="40.7904000000016">
    <ComboBox.ItemTemplate>
      <DataTemplate>
        <TextBlock Foreground="Black" Grid.Column="1" Margin="2, 1" Text="{Binding Name}" />
      </DataTemplate>
    </ComboBox.ItemTemplate>
    <ComboBox.ItemContainerStyle>
      <Style TargetType="{x:Type ComboBoxItem}">
        <Setter Property="Foreground" Value="Black" />
      </Style>
    </ComboBox.ItemContainerStyle>
  </ComboBox>

Upvotes: 0

Related Questions