0
votes

I have some controls in a Canvas. I need to animate their Canvas.Top and Canvas.Left properties. I'm using a foreach where I start all the animation:

foreach (Control c in controls)
{
   tc.BeginAnimation(Canvas.TopProperty, yAnimation);
   tc.BeginAnimation(Canvas.LeftProperty, xAnimation);
}

where xAnimation and yAnimation are two DoubleAnimation. Everything works fine, but after animating these object I can't drag them anymore. I found here the reason and the solution (setting the final value inside the animation Complete event handler), but it doesn't seem to work for me: in my problem I have a bunch of objects, and in animation Completed event handler I have no way to get which object's animation ended. Any ideas?

2

2 Answers

0
votes

Did you try the way described first in your link?

Set the animation's FillBehavior property to Stop

0
votes

I solved in this way: when each animation completes, this delegate is executed:

xAnimation.Completed += delegate
{
   if (++completedXAnimations == n)
   {
       setFinalXValues(items);
   }
};

Method setFinalXValues(items) removes animations and sets final values for all the items involved in the animation. Not a nice way, but it works. If you have any better ideas please post them.