BackgroundColor Items ComboBox WPF

我正在做一个WPF,并有一个comboBox,其中包含计算机上可用端口的列表。 我想改变这些物品的颜色。

我的comboBox是这些:

 

这些是加载它的方法:

 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; } 

我尝试了很多东西,但没有任何作用。 有人知道怎么做吗? 谢谢!!

要更改单个项目的背景颜色,您可以更改ItemContainerStyle ,例如:

   ...    ...  

这会将ComboBoxItem上的背景颜色设置为Blue