I am doing a WPF and have a comboBox which has a list of the avaible ports on the computer. I want to change the color of these items.
My comboBox is these:
<ComboBox HorizontalAlignment="Left" Margin="445,0,0,0" VerticalAlignment="Top" Width="120" Loaded="ComboBoxLoaded" SelectionChanged="ComboBoxSelectionChanged" Grid.Column="1" Background="#849096" Foreground="White"/>
And these is the method to loaded it:
private void ComboBoxLoaded(object sender, RoutedEventArgs e)
{
string [] portsList = PrintPorts();
// get the ComboBox reference
var comboBox = sender as ComboBox;
// assign the ItemsSource to the List
comboBox.ItemsSource = portsList;
// make the first item selected
comboBox.SelectedIndex = 0;
}
I was trying a lot of things but nothing works. Someone knows how to do it? Thanks!!
To change the background color of the individual items you can change the
ItemContainerStyle
, something like:This will set the background color on the
ComboBoxItem
s toBlue