Reputation: 601
So I have a Storyboard
that will run multiple animations one after each other (not all of them simultaneously) and in some of those animations I subscribe to the DoubleAnimation.Completed
event. The animations run perfectly fine, but the Completed
event of the animations are only triggered once the whole Storyboard
is finished, not when the individual animation is finished (BeginTime
of next animation). For example:
Storyboard storyboard = new Storyboard();
DoubleAnimation hideAnimation = new DoubleAnimation();
hideAnimation.Duration = TimeSpan.FromSeconds(0.5);
hideAnimation.BeginTime = TimeSpan.FromSeconds(0);
hideAnimation.From = 1.0;
hideAnimation.To = 0.0;
hideAnimation.Completed += new EventHandler(HideAnimation_Completed);
Storyboard.SetTarget(hideAnimation, grid1);
Storyboard.SetTargetProperty(hideAnimation, new PropertyPath(Grid.OpacityProperty));
DoubleAnimation showAnimation = new DoubleAnimation();
showAnimation.Duration = TimeSpan.FromSeconds(0.5);
showAnimation.BeginTime = TimeSpan.FromSeconds(0.5);
showAnimation.From = 1.0;
showAnimation.To = 0.0;
showAnimation.Completed += new EventHandler(ShowAnimation_Completed);
Storyboard.SetTarget(showAnimation, grid2);
Storyboard.SetTargetProperty(showAnimation, new PropertyPath(Grid.OpacityProperty));
storyboard.Children.Add(hideAnimation);
storyboard.Children.Add(showAnimation);
storyboard.Begin();
In this example HideAnimation_Completed
will be called after 1 second (total duration of storyboard
) and after HideAnimation_Completed
is done, ShowAnimation_Completed
is called.
Is was expecting HideAnimation_Completed
to be called after 0.5 seconds and ShowAnimation_Completed
after 1 second, not both after 1 second.
Those anyone knows if this an intended behaviour of WPF or am I missing something?
NOTE: The previous code is just an example to explain the problem I have. In my real program I have multiple animations that are dynamically generated and added into a global Storyboard
at different parts of the the class. So the idea of starting each animation at the end of the previous one using the Completed
event and UIElement.BeginAnimation
method, is the last of my resources since that would involve modifying quite a lot of my code (and it would probably have a great effect over the performance of my application).
Upvotes: 4
Views: 1122