我有一些文本框,当我将鼠标放在它们上面时,我想更改它们的一些属性。在这种情况下,我想更改 BorderBrush 和 BorderThickness。
这是我的 XAML ControlTemplate,它在Window.Resource
标签内:
<Style TargetType="{x:Type TextBox}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBoxBase}">
<Border
Name="Border"
Padding="4"
BorderBrush="#ccc"
BorderThickness="1">
<ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
<Border.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#FFC4C4C4" Offset="0.0" />
<GradientStop Color="#FFF8F8F8" Offset="0.10" />
</LinearGradientBrush>
</Border.Background>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver">
<Setter Property="BorderThickness" Value="1"></Setter>
<Setter Property="BorderBrush" Value="Orange"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Trigger
当鼠标光标在文本框上时,这段代码应该设置我在标签内写的属性:
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver">
<Setter Property="BorderThickness" Value="1"></Setter>
<Setter Property="BorderBrush" Value="Orange"></Setter>
</Trigger>
</ControlTemplate.Triggers>
但是这个触发器根本不会被解雇。什么都没发生。为什么?我怎样才能做到这一点?