How to stop an animation in C# / WPF?


Question

I have something like this:

barProgress.BeginAnimation(RangeBase.ValueProperty, new DoubleAnimation(
    barProgress.Value, dNextProgressValue,
    new Duration(TimeSpan.FromSeconds(dDuration)));

Now, how would you stop that animation (the DoubleAnimation)? The reason I want to do this, is because I would like to start new animations (this seems to work, but it's hard to tell) and eventually stop the last animation...

1
47
8/21/2008 3:45:24 PM

Accepted Answer

To stop it, call BeginAnimation again with the second argument set to null.

75
6/28/2018 2:54:41 PM

When using storyboards to control an animation, make sure you set the second parameter to true in order to set the animation as controllable:

public void Begin(
    FrameworkContentElement containingObject,
    **bool isControllable**
)

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon