Andrew Simpson
Andrew Simpson

Reputation: 7354

Changing BackGround color of combobox when ItemsSource is set

I have a wpf c# app.

I am using a combo box and I set the ItemsSource to my Observable collection.

what I would like is the background of the combo box not to be grey.

This control is housed in a UserControl.

<UserControl x:Class="InformedWorkerClient.UserControls.ucJobStatus"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:InformedWorkerClient.UserControls"
         mc:Ignorable="d" 
         d:DesignHeight="27" d:DesignWidth="300" Background="White">
<Grid Background="White">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>


    <ComboBox x:Name="cboJobStatus" Grid.Row="0" Grid.Column="0" Background="White"
        DisplayMemberPath="Description" 
        SelectedValuePath="JobStatusRef" 
        SelectedValue="{Binding Path=JobStatus}" SelectionChanged="cboJobStatus_SelectionChanged" />
</Grid>

Additional:

This is what the background looks like after item is selected. I want the background to be white

enter image description here

Upvotes: 0

Views: 836

Answers (2)

Kory Gill
Kory Gill

Reputation: 7161

You cannot do this due to a bug in the ControlTemplate for ComboBox.

Potential solution is to copy/edit the template and create your own.

This question is a duplicate. Perhaps the answer there can be updated with some more information. I searched for wpf cant change background of combobox and the top link is the MSDN answer on how to copy the template but even then the solution is riddled with issues with different Windows versions, aero theming, and does not address situations where users have high contrast turned on, and other accessibility issues.

Upvotes: 1

Jay Kim
Jay Kim

Reputation: 73

I would recommend to use <ComboBox.ItemContainerStyle> and setup Background to Transparent for the container. Then each item background will be as in the ComboBox.

Upvotes: 0

Related Questions