Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
After applying transaleTransform on ellipse , it's position not getting change. graphically it's position get change on canvas. But when getting it's position by below code it's postion remain same.

C#
Point pt = new Point();
           pt.X = (double)el.GetValue(Canvas.LeftProperty);
           pt.Y = (double)el.GetValue(Canvas.TopProperty);




code for translating it

C#
 TranslateTransform offsetTransform = new TranslateTransform();
                
                DoubleAnimation offsetXAnimation = new DoubleAnimation(0,dx, new Duration(TimeSpan.FromSeconds(duration)));
                DoubleAnimation offsetYAnimation = new DoubleAnimation(0,dy, new Duration(TimeSpan.FromSeconds(duration)));
                //offsetXAnimation.RepeatBehavior = RepeatBehavior.Forever;
                offsetXAnimation.BeginTime = TimeSpan.FromSeconds(delay);
                offsetTransform.BeginAnimation(TranslateTransform.XProperty, offsetXAnimation);
                offsetTransform.BeginAnimation(TranslateTransform.YProperty, offsetYAnimation);
ellipse.RenderTransform = offsetTransform;
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jan-13 17:30pm    
Where do you think you do it? :-)
—SA
footballpardeep 3-Jan-13 4:37am    
Let me explain one more time , what i am doing. Suppose an ellipse is at 100,200 position. i am translating it to position 400,500 by double animation (code is pasted in question). graphically ellipse changes it postion to 400,500. But now, when i select this ellipse to get it's position (by using ellipse.getvalue(Canvas.leftproperty)) , it' showing me 100,200.

1 solution

I cannot set where do you update the properties related to the position of Ellipse.

I would agree that you do if I saw something like
C#
myCanvas.SetLeft(MyEllipse, displacementX);
myCanvas.SetTop(MyEllipse, displacementY);


Please see:
http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.settop.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.setleft.aspx[^].

Now about the animation. I cannot see where you animate the position of a UIElement of Canvas. You do it to the TranslateTransform, which is a right approach, but you should not expect that any dependency property of you UIElement are updated. These are just different things.

—SA
 
Share this answer
 
Comments
footballpardeep 3-Jan-13 4:39am    
what i am doing. Suppose an ellipse is at 100,200 position. i am translating it to position 400,500 by double animation (code is pasted in question). graphically ellipse changes it postion to 400,500. But now, when i select this ellipse to get it's position (by using ellipse.getvalue(Canvas.leftproperty)) , it' showing me 100,200.
Sergey Alexandrovich Kryukov 3-Jan-13 11:31am    
Right, because you do not animate this property; you animate the transform.
—SA
footballpardeep 3-Jan-13 4:41am    
i can change the postion of ellipse directly by ellipse.setValue(Canvas.leftProperty,point.X); ellipse.setvalue(Canvas.TopProperty.point.Y). But i want animating effect.
Sergey Alexandrovich Kryukov 3-Jan-13 11:30am    
Right. Do you have animated effect by TranslateTransform? If you do, what's wrong about it. If you do not, what's going on? You were not asking about animation itself; you were asking about the resulting value of that dependency property...
Keep in mind that you can always achieve fully custom animation using an extra thread and Dispatcher.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900