I’m animating something in my Windows 8 app from code behind. I have a collection of animation objects, each containing a DoubleAnimation. I call a method which iterates over this collection, creates new Storyboard objects for each one and begins them. Regardless of whether I set BeginTime on the storyboard, DoubleAnimation or both, they all start and run at the same time.
How do I delay an animation by a set number of milliseconds?
foreach (AnimationObject a in queue)
{
Storyboard sb = new Storyboard();
sb.Duration = a.DoubleAnimation.Duration;
sb.BeginTime = a.DoubleAnimation.BeginTime;
sb.Children.Add(a.DoubleAnimation);
Storyboard.SetTarget(a.DoubleAnimation, a.Target);
Storyboard.SetTargetProperty(a.animation, a.TargetProperty);
sb.Begin();
}
I wrote a queue instead which uses await Task.Delay(a.BeginTime) and this works, so I know I’m setting BeginTime correctly. However the Task Delay approach doesn’t seem very efficient
My issue was that later
Storyboards targeting the sameTargetwere overriding previous ones. I re-engineered my queue to useDoubleAnimationUsingKeyFramesìnstead, and to add keyframes to an existingStoryboardwhere one was present. All working perfectly now!