wpf 设置 ComboBox 选中项高亮颜色

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1278144/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:50:22  来源:igfitidea点击:

Set ComboBox selected item highlight color

wpfcomboboxhighlightselected

提问by Klay

I need to change the highlight color of a ComboBox's selected item in the popup list. I've found several tutorials explaining how to do this, but all of them either use Blend, which I do not have and cannot obtain, or involve changing the system default colors--which seems like a hack to me.

我需要更改弹出列表中组合框所选项目的突出显示颜色。我找到了几个解释如何做到这一点的教程,但他们要么使用我没有也无法获得的 Blend,要么涉及更改系统默认颜色——这对我来说似乎是一个黑客。

Can someone point me to the template I need to override, or tell me the property I need to set?

有人可以指出我需要覆盖的模板,或者告诉我需要设置的属性吗?

回答by Kent Boogaart

Override the SystemColors.HighlightBrushKey(and SystemColors.HighlightTextBrushKeyif you want):

覆盖SystemColors.HighlightBrushKeySystemColors.HighlightTextBrushKey如果需要):

<ComboBox>
    <ComboBox.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}">Red</SolidColorBrush>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}">Blue</SolidColorBrush>
    </ComboBox.Resources>
    <ComboBoxItem>One</ComboBoxItem>
    <ComboBoxItem>Two</ComboBoxItem>
</ComboBox>

回答by Klay

I have created a template for Combobox here :

我在这里为 Combobox 创建了一个模板:

http://wpfstyles.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=31388#DownloadId=78720

http://wpfstyles.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=31388#DownloadId=78720

Thanks, Vikas

谢谢,维卡斯