WPF 文本框边框何时被选中?
我想让 WPF 文本框具有深蓝色边框且厚度等于 1。即使选择了文本框,我也想让 WPF 具有此边框(深蓝色,厚度设置为 1)。
我尝试通过以下代码完成此任务。然而,它根本不起作用。 有什么想法或提示吗?任何帮助将不胜感激。
<Style x:Key="ReadOnlyLargeTextBox" TargetType="{x:Type TextBox}" >
<Setter Property="Height" Value="80"/>
<Setter Property="MaxHeight" Value="80"/>
<Setter Property="VerticalScrollBarVisibility" Value="Visible"/>
<Style.Triggers>
<Trigger Property="TextBox.IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="DarkBlue"/>
<Setter Property="BorderThickness" Value="1"/>
</Trigger>
<Trigger Property="TextBox.IsMouseOver" Value="False">
<Setter Property="BorderBrush" Value="DarkBlue"/>
<Setter Property="BorderThickness" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>
PS 请注意,文本框没有 IsSelected 属性。
I want to make a WPF TextBox have a DarkBlue border and thickness equal to 1. I want to make the WPF have this border ( DarkBlue, thickness set to 1 ) even when the TextBox is selected.
I tried doing this task by the following code. However, it doesn't work at all. Any ideas or hints ? Any help would be greatly appreciated.
<Style x:Key="ReadOnlyLargeTextBox" TargetType="{x:Type TextBox}" >
<Setter Property="Height" Value="80"/>
<Setter Property="MaxHeight" Value="80"/>
<Setter Property="VerticalScrollBarVisibility" Value="Visible"/>
<Style.Triggers>
<Trigger Property="TextBox.IsMouseOver" Value="True">
<Setter Property="BorderBrush" Value="DarkBlue"/>
<Setter Property="BorderThickness" Value="1"/>
</Trigger>
<Trigger Property="TextBox.IsMouseOver" Value="False">
<Setter Property="BorderBrush" Value="DarkBlue"/>
<Setter Property="BorderThickness" Value="1"/>
</Trigger>
</Style.Triggers>
</Style>
P.S Note that the text box does not have an IsSelected property.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看看这是你想要的...
just see is this you want...
我认为您的问题是由于触发器属性值包含TextBox。您只需要该房产的名称。
I think your problem is due to having the Trigger Property value containing TextBox. You just need the name of the property.
检查 FrameworkElement 对象(祖先的文本框)。其目的是定义选择元素时应用的样式。
Check FocusVisualStyle property of the FrameworkElement object (ancestor of TextBox). It's purpose is to define style applied when an element is selected.
当“IsMouseOver”为 True 和 False 时,您具有相同的逻辑。换一个,你应该会看到一些东西。
You have the same logic for when "IsMouseOver" True as well False. Change one and you should see something.