如何更改 WPF 文本框的突出显示文本颜色? [英] How can you change the highlighted text color for a WPF TextBox?

查看:33
本文介绍了如何更改 WPF 文本框的突出显示文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

WPF TextBox 本机使用系统突出显示颜色来绘制选定文本的背景.我想覆盖它并使其保持一致,因为它因操作系统/用户主题而异.

The WPF TextBox natively makes use of the System Highlight color for painting the background of selected text. I would like to override this and make it consistent since it varies by OS/user theme.

对于 ListBoxItem,有一个 巧妙技巧(见下文),您可以在其中覆盖 HighlightBrushKey 在焦点设置中自定义系统高亮颜色:

For ListBoxItems, there is a neat trick (see below) where you can override the resource key for the HighlightBrushKey to customize the System Highlight color in a focused setting:

<Style TargetType="ListBoxItem">
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                         Color="LightGreen"/>
    </Style.Resources>
</Style>

不幸的是,同样的技巧不适用于 TextBox.除了覆盖 ControlTemplate"之外,还有其他人有什么想法吗?

The same trick does not work for the TextBox unfortunately. Does anyone have any other ideas, besides "override the ControlTemplate"?

注意:这行为似乎已添加到 WPF 4.

推荐答案

正如史蒂夫所说:注意:此行为似乎已添加到 WPF 4.

我遇到了同样的问题.

正如 WPF 博士所说的

As Dr.WPF says

这完全不可能当前的 .NET 版本(3.0 和 3.5贝塔).该控件被硬编码为使用系统设置...它没有完全看控制模板."

"It is entirely impossible in the current .NET releases (3.0 & 3.5 beta). The control is hardcoded to use the system setting... it doesn't look at the control template at all."

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/bbffa6e3-2745-4e72-80d0-9cdedeb69f7f/

这篇关于如何更改 WPF 文本框的突出显示文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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