Home > Software engineering >  How to make WPF ComboBox items background Visible?
How to make WPF ComboBox items background Visible?

Time:11-02

  <Grid Grid.Row="5" Grid.Column="1">

      <ComboBox Cursor="Hand" SelectedItem="{Binding SelectedRealEstate}" Background="White"  
                 Name="cbbRealEstates"  ItemsSource="{Binding RealEstateSummary}"/>

   </Grid>

the code above gives me invisible item background

enter image description here

How do I make the background visible?

CodePudding user response:

According to this,

You will have to set the styles in the resources of the element. In my case it's a window. So it's

 <Window.Resources>
    <Style x:Key="ComboBoxItemStyle" TargetType="ComboBoxItem">
        <Setter Property="Background" Value="Blue" />
    </Style>
    <Style x:Key="ComboBoxStyle" TargetType="ComboBox">
        <Setter Property="ItemContainerStyle" Value="{StaticResource ComboBoxItemStyle}" />
    </Style>
</Window.Resources>

Set a style for ComboBoxItem. And use that style when you set the style for the ComboBox

Then apply the Combobox Style to the element.

<ComboBox Name="myCmb" Style="{StaticResource ComboBoxStyle}">
  • Related