tags:

views:

43

answers:

2

Hi, 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?

A: 

Did you try the way described first in your link?

Set the animation's FillBehavior property to Stop

winSharp93
Yes, I tried. The problem is: when animation is completed I should set the definitive value in the event handler, but I don't know which is the control involved. Let's suppose I have 3 controls c1, c2 and c3. I want they Canvas.Top property go to 10 for c1, 20 for c2 and 30 for c3. With animations this works fine. When animation is completed, I should set manually c1's Top property to 10, c2's to 20 and c3's to 30 in Completed event handler. How can I know which of these 3 controls completed the animation and should be set to the definitive value?
loris
A: 

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.

loris