I have an issue with ComboBox highlighting which shows black text on a blue background, when the text for highlighting should be white.
I have examples of ComboBox which use ComboBoxItems where the Content is a string. The combobox in these cases behave as expected - when the combobox is dropped down if you highlight an item it displays white text on a blue blackground.
However I have an example ComboBox where the Content of each ComboBoxItem is a Grid (the Grid contains 2 columns - the first which contains text and the second a line - it is a line thickness combobox). In this case when the combobox is dropped down, if you highlight an item it displays black text on a blue background instead of white text. Note: even if i remove the line part and so just have one column containing text I still see the issue.
The nearest I have come to solving the issue is to add a resource to the combobox for SystemColors.HighlightBrushKey and SystemColors.HighlightTextBrushKey where I set the colour of the brush. However, SystemColors.HighlightBrushKey does correctly change the back colour of the highlight (this is not what I want though), and when I try to use SystemColors.HighlightTextBrushKey which I thought would change the text colour of a highlighted item nothing happens (the colour does not change).
Example edited code:
var combo = new ComboBox();
Func<double, object> build = d =>
{
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition {Width = GridLength.Auto});
var label = new Label {Content = d};
grid.Children.Add(label);
Grid.SetColumn(label, 0);
var comboBoxItem = new ComboBoxItem {Content = grid, Tag = d};
return comboBoxItem;
};
combo.Items.Add(build(0.5));
combo.Items.Add(build(1));
combo.Items.Add(build(2));
...
I have tried:
combo.Resources.Add(SystemColors.HighlightBrushKey, Brushes.Green); // this does set the back to green (but is not what I want)
combo.Resources.Add(SystemColors.HighlightTextBrushKey, Brushes.White); // this does not change the text colour to white it stays as black
Any help appreciated, thanks.