我正在进行一个WPF项目,其中有一个下拉框,列出了计算机上可用的端口。我想要改变这些选项的颜色。
我的下拉框如下:
这是加载它的方法:
我尝试了很多方法,但都没有起作用。有人知道怎么做吗?谢谢!!
我的下拉框如下:
<ComboBox HorizontalAlignment="Left" Margin="445,0,0,0" VerticalAlignment="Top" Width="120" Loaded="ComboBoxLoaded" SelectionChanged="ComboBoxSelectionChanged" Grid.Column="1" Background="#849096" Foreground="White"/>
这是加载它的方法:
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;
}
我尝试了很多方法,但都没有起作用。有人知道怎么做吗?谢谢!!