设置 ComboBox 选中的项目高亮颜色 [英] Set ComboBox selected item highlight color

查看:51
本文介绍了设置 ComboBox 选中的项目高亮颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更改弹出列表中组合框所选项目的突出显示颜色.我找到了几个解释如何执行此操作的教程,但所有教程都使用我没有也无法获得的 Blend,或者涉及更改系统默认颜色——这对我来说似乎是一种黑客行为.

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.

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

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

推荐答案

覆盖 SystemColors.HighlightBrushKey(如果需要,还可以覆盖 SystemColors.HighlightTextBrushKey):

Override the SystemColors.HighlightBrushKey (and SystemColors.HighlightTextBrushKey if you want):

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

这篇关于设置 ComboBox 选中的项目高亮颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆