Sonhja
Sonhja

Reputation: 8448

How to stop an animation in WPF

I have the following code to start an animation that it's located in my Resources:

 Storyboard _wheelAnimation = FindResource("CircleRotation") as Storyboard;
 if (_wheelAnimation == null) return;
 _wheelAnimation.Begin(this);

Here is my animation:

<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>

I want to stop it programmatically, and I tried this:

_wheelAnimation.Stop();  // and also _wheelAnimation.Stop(this);

With no luck... any idea on why it's not stopping?

Upvotes: 1

Views: 2052

Answers (2)

Bahman_Aries
Bahman_Aries

Reputation: 4798

When using Begin, Set the second parameter (IsControllable) to true in order to make the Stop method work:

_wheelAnimation.Begin(this, true);
_wheelAnimation.Stop(this);

Upvotes: 4

Ben Cohen
Ben Cohen

Reputation: 1410

Try _wheelAnimation.SkipToFill();

Upvotes: -1

Related Questions