如何更改WPF文本框的突出显示的文本颜色? [英] How can you change the highlighted text color for a WPF TextBox?
问题描述
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.
For ListBoxItem
s, 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
"?
谢谢您的建议!
推荐答案
正如史蒂夫所说:我遇到了同样的问题.
I bumped into the same problem.
WPF博士所说
在 当前的.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."
>: //social.msdn.microsoft.com/Forums/zh-CN/wpf/thread/bbffa6e3-2745-4e72-80d0-9cdedeb69f7f/
这篇关于如何更改WPF文本框的突出显示的文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!