« Silverlight Egg Timer | Main | Getting WPF/E Intellisense After Using Expression Design »

Multiple Storyboard Animations in WPF/E

This was a bit of a head-scratcher. I was experimenting with multiple animations (for the sake of argument, let's say two: "upAnim" and "downAnim") in a simple WPF/E application, and could get them to work - but not repeatedly. They'd both work - just once - and then only the one declared last in the XAML would be callable. Switch 'em around, same behavior. They'd both work once, then only the one declared last would run again.

(Strangely, the "completed" event of the non-playing animation would still fire, and at the correct time, i.e, if the animation was supposed to take five seconds, the event would fire after five seconds even though the animation didn't play.)

The answer is this: make sure to explicitly stop any other playing storyboards before starting a new one. (Yes, even if the first one stopped an hour ago.) So instead of just calling the Begin method of the storyboard, call:

sender.findName("downAnim").Stop();
sender.findName("upAnim").Begin();

That should do the trick.

(Note: just read on a Microsoft board that you should start the new one before stopping the old one - this seems counter-intuitive to me, and my examples seem to work either way, but just passing it on.)

Posted on Friday, December 8, 2006 at 02:17PM by Registered CommenterSimon Allardice | Comments1 Comment

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (1)

Can you post your code here? I'm trying to do multiple storyboards in silverlight 1.1a and it blows up while trying to initialize the xaml. I can't seem to figure out how to get multiple storyboards in a single canvas.
July 22, 2007 | Unregistered CommenterJustin Chase
Editor Permission Required
You must have editing permission for this entry in order to post comments.