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

Reader Comments (1)