【发布时间】:2011-01-15 09:18:44
【问题描述】:
当突出显示的文本应该是白色时,我遇到了 ComboBox 突出显示的问题,它在蓝色背景上显示黑色文本。
我有使用 ComboBoxItems 的 ComboBox 示例,其中 Content 是一个字符串。在这些情况下,组合框的行为与预期一样 - 如果您突出显示某个项目,下拉组合框时,它会在蓝黑色背景上显示白色文本。
但是,我有一个示例 ComboBox,其中每个 ComboBoxItem 的内容是一个网格(网格包含 2 列 - 第一列包含文本,第二列包含线条 - 它是线条粗细组合框)。在这种情况下,当下拉组合框时,如果突出显示一个项目,它会在蓝色背景上显示黑色文本,而不是白色文本。注意:即使我删除了行部分,所以只有一列包含文本,我仍然会看到问题。
我最接近解决问题的方法是将资源添加到 SystemColors.HighlightBrushKey 和 SystemColors.HighlightTextBrushKey 的组合框中,我在其中设置画笔的颜色。但是, SystemColors.HighlightBrushKey 确实正确地改变了突出显示的背景颜色(但这不是我想要的),当我尝试使用 SystemColors.HighlightTextBrushKey 时,我认为它会改变突出显示项目的文本颜色,没有任何反应(颜色不变)。
示例编辑代码:
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));
...
我试过了:
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
任何帮助表示赞赏,谢谢。
【问题讨论】: