gpt4 book ai didi

WPF TextBox 丑边框问题

转载 作者:行者123 更新时间:2023-12-04 23:11:00 25 4
gpt4 key购买 nike

我想覆盖 WPF 中的默认 TextBox 边框。我有这种适用于所有文本框的样式。

<!-- StyleTextBox-->
<Style x:Key="StyleTextBox" TargetType="{x:Type TextBox}">
<Setter Property="MinHeight" Value="20" />
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Margin" Value="3"/>
<Setter Property="IsEnabled" Value="{DynamicResource WriteAble}"/>
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="{StaticResource ButtonFont_DarkGray}" />
<Style.Triggers>
<!--Resolves multiline textbox vertical alignment problem-->
<Trigger Property="TextWrapping" Value="NoWrap">
<Setter Property="VerticalContentAlignment" Value="Center" />
</Trigger>
</Style.Triggers>
</Style>

我加了 SnapsToDevicePixels="True"以在 LCD 显示器上正确显示边框。

但是,每个 TextBox 似乎都不同。一些边框丢失,或灰色..
有谁知道为什么?

最佳答案

您可以尝试编辑文本框的模板并将边框名称 Bd 更改为“真实”边框而不是 chrome 边框。像这样:

<ControlTemplate x:Key="TextBoxBaseControlTemplate1" 
TargetType="{x:Type TextBoxBase}">
<Border x:Name="Bd" SnapsToDevicePixels="True"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}" >
<ScrollViewer x:Name="PART_ContentHost"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Background" TargetName="Bd"
Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>

将此 setter 添加到您的样式以启用模板:
<Setter Property="Template" 
Value="{DynamicResource TextBoxBaseControlTemplate1}"/>

关于WPF TextBox 丑边框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1124069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com