How to move a figure on canvas in WPF?

I added a rectangle to the canvas, like this:

Canvas.SetTop(myRectangle, 150);
Canvas.SetLeft(myRectangle, 80);
canvas.Children.Add(myRectangle);

Now I want to move the rectangle to another place, say (100, 100). What is the best way to do this?

Thank!

+3
source share
1 answer

If you just want it right there, you will again call SetTop and SetLeft. Otherwise, you would use StoryBoard, perhaps with two DoubleAnimationUsingKeyFrames elements that set the Top and Left properties, should change from 150/80 to 100/100 within the required time period (1 keyframe for the initial value, 1 keyframe for the final value).

+3
source

Source: https://habr.com/ru/post/1727270/


All Articles