Xaml 控制模板触发器
上面的代码是我当前用于文本框的代码。我在ControlTemplate.Trigger中放置了什么,以便我的边框从黑色变为蓝色,或者在单击时增加边框大小。我试过几件事,但运气不好。这包括样式、触发器和事件。请发布ControlTemplate.Trigger之间的代码 这假设您希望在聚焦边框时更改边框,因为单击文本框会聚焦边框。没有OnClick属性可用,这会在聚焦文本框后更改其边框Xaml 控制模板触发器,xaml,triggers,textbox,Xaml,Triggers,Textbox,上面的代码是我当前用于文本框的代码。我在ControlTemplate.Trigger中放置了什么,以便我的边框从黑色变为蓝色,或者在单击时增加边框大小。我试过几件事,但运气不好。这包括样式、触发器和事件。请发布ControlTemplate.Trigger之间的代码 这假设您希望在聚焦边框时更改边框,因为单击文本框会聚焦边框。没有OnClick属性可用,这会在聚焦文本框后更改其边框 <Style TargetType="{x:Type TextBox}"> <
<Style TargetType="{x:Type TextBox}">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="MinWidth" Value="120" />
<Setter Property="MinHeight" Value="25" />
<Setter Property="AllowDrop" Value="true" />
<Setter Property="FontSize" Value="16"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border Name="Border" CornerRadius="6" Padding="2" BorderBrush="Black" BorderThickness="2,1">
<ScrollViewer Margin="0" x:Name="PART_ContentHost" />
</Border>
<ControlTemplate.Triggers>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这将正确地从您的
文本框中删除焦点,从而取消触发器设置,使其再次出现黑条。您尝试了一些方法,比如什么?我在上面提到过。比如使用style.trigger和一些事件之类的东西。我基本上都试过了,但都没办法。谢谢,成功了。如果我单击“退出”,如何使其恢复正常?好吧,一旦键盘焦点消失,它应该会恢复正常颜色。如果你有另一个文本框,你点击后进入它,它能工作吗?是的,它能。我想会的,但我想如果他们点击屏幕上的某个地方,我不想让它显示出来。我想考虑一下,这一刻其实并不重要。你应该能够用这些答案让这种行为起作用()。当您没有在其他位置设置键盘焦点时,默认行为不会删除键盘焦点。我如何仅在样式表中执行此操作。我将我的样式表连接到一个.cs文件
<Trigger Property="IsKeyboardFocusWithin"
Value="True">
<Setter Property="BorderBrush"
TargetName="Border"
Value="Blue"/>
</Trigger>
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
Keyboard.ClearFocus();
}