文字框样式 [英] Text box styling
本文介绍了文字框样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每当我尝试将样式应用于文本框时,该样式都将对用户输入无响应.您能告诉我一种解决方法吗?这是我正在使用的xaml代码:
Whenever I try to apply a style to a textbox, it becomes unresponsive to user input. Can you tell me a way to solve this?Here is the xaml code I am using:
<Style x:Key="textbox"
TargetType="TextBox">
<Setter Property="OverridesDefaultStyle"
Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border BorderThickness="3"
Background="{TemplateBinding Background}"
Name="border">
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="border"
Property="BorderBrush"
Value="#9E5971" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
推荐答案
替换
<ContentPresenter
HorizontalAlignment="Center" VerticalAlignment="Center" />
使用
<ScrollViewer
x:Name="PART_ContentHost"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
名为 PART_ContentHost
的
ScrollViewer
是任何 TextBox
控件模板的必需部分.您应该使用默认WPF控件样式和模板作为参考,而不是提出来使用您自己的模板.
ScrollViewer
named PART_ContentHost
is a mandatory part of any TextBox
control template. You should use Default WPF Control Styles and Templates as reference instead of coming up with your own template.
这篇关于文字框样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文