tags:

views:

6160

answers:

6

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

+7  A: 

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

DannySmurf
+2  A: 

Ah, that is just so... intuitive!

Who would of thought to call BeginAnimation() to stop one?

Daren Thomas
+2  A: 

Place the animation in a StoryBoard. Call Begin() and Stop() on the storyboard to start to stop the animations.

Brian Leahy
+3  A: 

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 )

Plus one to you, I was wondering why my animation did not respond to "Stop"!
Joon
+4  A: 

If you want the base value to become the effective value again, you must stop the animation from influencing the property. There are three ways to do this with storyboard animations:

  • Set the animation's FillBehavior property to Stop
  • Remove the entire Storyboard
  • Remove the animation from the individual property

From MSDN

How to: Set a Property After Animating It with a Storyboard

iik
A: 

Hey!

In my case I had to use two commands, my xaml has a button which fires a trigger, and its trigger fires the storyboard animation.

I've put a button to stop animation with this code behind:

MyBeginStoryboard.Storyboard.Begin(this, true);
MyBeginStoryboard.Storyboard.Stop(this);

I don't like it but it really works here. Give it a try!

Junior Mayhé