您可以通过以下方式为线性渐变设置动画:
<Storyboard x:Key="Focused" >
<DoubleAnimation Duration="0:0:0.3" Storyboard.TargetProperty=
"BorderBrush.GradientStops[0].Offset" Storyboard.TargetName="Bd"/>
</Storyboard>
到目前为止还好。您可以设置一种颜色来对其进行动画处理。如何将 To 属性设置为指向您已有的渐变资源?
是否可以在没有偏移的情况下使用borderbrush目标属性?在大多数情况下,我需要完全切换渐变。
编辑:
好的,那么我如何使用颜色动画从一个渐变偏移淡入另一个,其中目标颜色不是硬编码的,而是来自资源?
例子:
<!-- @ MouseOver -->
<LinearGradientBrush x:Key="MouseOverBrush" StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#FF656565" Offset="0"/>
<GradientStop Color="#33656565" Offset="1"/>
</LinearGradientBrush>
<Style x:Key="CheckBoxStyle" TargetType="{x:Type CheckBox}">
<Setter Property="Foreground" Value="{StaticResource CheckBoxForeground}"/>
<Setter Property="Background" Value="{StaticResource CheckBoxGradientBrush}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<Border x:Name="Bd"
Background="{TemplateBinding Background}">
<ContentPresenter
Content="{TemplateBinding Content}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
RecognizesAccessKey="True"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Bd" Property="Background" Value="{StaticResource MouseOverBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
如果我想在鼠标悬停到鼠标悬停时为 bd 的背景设置动画,我该怎么做?