我坚持使用 WPF 中的样式。当用户将鼠标悬停在按钮上时,我需要更改背景渐变,但我不知道如何进行更改。这是我到目前为止的代码:
<Style x:Key="Button_Green" TargetType="{x:Type Button}">
<Setter Property="FontSize" Value="11" />
<Setter Property="Foreground" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border CornerRadius="2" BorderBrush="#387f38" BorderThickness="1">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF5BB75B" Offset="0" />
<GradientStop Color="#FF449B44" Offset="1" />
</LinearGradientBrush>
</Border.Background>
<ContentPresenter x:Name="ButtonContentPresenter" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF5BB75B" Offset="0" />
<GradientStop Color="#FF398239" Offset="1" />
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Cursor" Value="Hand" />
</Trigger>
</Style.Triggers>
</Style>
鼠标光标正常变化,但背景渐变没有变化。