如何在 WPF 中停止动画
How to stop an animation in WPF
我有以下代码来启动位于我的 Resources
中的动画:
Storyboard _wheelAnimation = FindResource("CircleRotation") as Storyboard;
if (_wheelAnimation == null) return;
_wheelAnimation.Begin(this);
这是我的动画:
<Storyboard x:Key="CircleRotation" RepeatBehavior="Forever">
<DoubleAnimation
Storyboard.TargetName="BigWheelImage"
Storyboard.TargetProperty="RenderTransform.Angle"
From="360" To="0" Duration="0:0:35" BeginTime="00:00:00.000" />
<DoubleAnimation
Storyboard.TargetName="SmallWheelImage"
Storyboard.TargetProperty="RenderTransform.Angle"
From="0" To="360" Duration="0:0:25" BeginTime="00:00:00.000" />
</Storyboard>
我想以编程方式停止它,我试过这个:
_wheelAnimation.Stop(); // and also _wheelAnimation.Stop(this);
运气不好...知道为什么它没有停止吗?
试试 _wheelAnimation.SkipToFill();
当使用 Begin
时,将第二个参数 (IsControllable
) 设置为 true 以使 Stop
方法起作用:
_wheelAnimation.Begin(this, true);
_wheelAnimation.Stop(this);
我有以下代码来启动位于我的 Resources
中的动画:
Storyboard _wheelAnimation = FindResource("CircleRotation") as Storyboard;
if (_wheelAnimation == null) return;
_wheelAnimation.Begin(this);
这是我的动画:
<Storyboard x:Key="CircleRotation" RepeatBehavior="Forever">
<DoubleAnimation
Storyboard.TargetName="BigWheelImage"
Storyboard.TargetProperty="RenderTransform.Angle"
From="360" To="0" Duration="0:0:35" BeginTime="00:00:00.000" />
<DoubleAnimation
Storyboard.TargetName="SmallWheelImage"
Storyboard.TargetProperty="RenderTransform.Angle"
From="0" To="360" Duration="0:0:25" BeginTime="00:00:00.000" />
</Storyboard>
我想以编程方式停止它,我试过这个:
_wheelAnimation.Stop(); // and also _wheelAnimation.Stop(this);
运气不好...知道为什么它没有停止吗?
试试 _wheelAnimation.SkipToFill();
当使用 Begin
时,将第二个参数 (IsControllable
) 设置为 true 以使 Stop
方法起作用:
_wheelAnimation.Begin(this, true);
_wheelAnimation.Stop(this);