WPF TextBox本身使用系统突出显示颜色来绘制所选文本的背景.我想覆盖它并使其保持一致,因为它因操作系统/用户主题而异.
对于ListBoxItems,有一个巧妙的技巧(见下文),您可以覆盖资源键以HighlightBrushKey在焦点设置中自定义系统突出显示颜色:
<Style TargetType="ListBoxItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightGreen"/>
</Style.Resources>
</Style>
Run Code Online (Sandbox Code Playgroud)
TextBox不幸的是,同样的技巧并不适用.有没有人有任何其他的想法,除了"覆盖ControlTemplate"?
谢谢你的任何建议!
我有一个DataGrid包含几个DataGridTemplateColumns.我的问题是当前选择的行将一些单元格前景变为白色,即使文本变为白色.
DataGridTemplateColumns包含TextBlocks的行为正确并变为白色,而DataGridTemplateColumns包含TextBoxs的行在选择行时不会更改.
有谁知道为什么或如何解决这个问题?
我尝试过这个解决方案:但它只能让TextBlocks受到影响,有人知道可能出现什么问题吗?
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)
如何更改此模板以覆盖突出显示的文本和背景颜色?