如何更改TextBox的突出显示文本颜色?

Dia*_*ana 2 .net wpf textbox background

WPF使用系统突出显示颜色来绘制所选文本的背景.我也想覆盖它.

我有一个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>
Run Code Online (Sandbox Code Playgroud)

如何更改此模板以覆盖突出显示的文本和背景颜色?

Dan*_*zey 6

在.NET 4中,您可以使用文本框的SelectionBrush属性.

早期版本要求您在代码中覆盖系统颜色,因为没有容易暴露的属性 - 文本框将只使用系统定义的值.