我有下面的 XAML,它试图将窗口中所有文本框的边框设置为红色 OnMouseOver。发生的情况是,当鼠标悬停在文本框上时,设置了 FontSize 和 Foreground 属性,但 BorderBrush 仅在恢复为之前的默认值之前暂时设置。我希望 BorderBrush 保持红色,直到鼠标不再位于文本框上方。任何想法为什么会发生这种情况?
<Window x:Class="StylesApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Width" Value="250" />
<Setter Property="Height" Value="50" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="FontSize" Value="20" />
<Setter Property="Foreground" Value="Red" />
<Setter Property="BorderBrush" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<TextBox>
My TextBox
</TextBox>
</Grid>
</Window>