如何更改突出显示的文本颜色为一个TextBox? [英] How can I change the highlighted text color for a TextBox?
问题描述
WPF使用该系统突出显示颜色画所选文本的背景。我想重写这一点。
WPF uses the system highlight color for painting the background of the selected text. I'd like to override it too.
我对的textBox控件模板:
I have a control template for textBox:
<ControlTemplate TargetType="TextBox">
<Border Name="Border"
CornerRadius="2"
Padding="2"
Background="Transparent"
BorderThickness="0" >
<ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="Border" Property="Background" Value="{StaticResource TextBoxDisabledBackgroundColor}"/>
<Setter Property="Foreground" Value="{StaticResource TextBoxDisabledForegroundColor}"/>
</Trigger>
<Trigger Property="IsReadOnly" Value="false">
<Setter TargetName="Border" Property="Background" Value="{StaticResource TextBoxBackgroundColor}"/>
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
我怎样才能改变这个模板覆盖高亮显示的文本和背景颜色?
How can I change this template to override the highlighted text and background color?
推荐答案
在.NET 4中,你可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.windows.controls.primitives.textboxbase.selectionbrush.aspx"相对=nofollow> SelectionBrush 文本框的属性。
In .NET 4 you can use the SelectionBrush property of the textbox.
早期版本要求您覆盖系统颜色IN-code,因为没有容易暴露属性本 - 文本框将只使用系统定义值
Earlier versions require you to override system colours in-code, as there was no easily-exposed property for this - the textbox would just use the system-defined values.
这篇关于如何更改突出显示的文本颜色为一个TextBox?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!