开发者

How to move a Shape on Canvas in WPF?

I added a Rectangle to开发者_开发技巧 a Canvas like this:

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

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

Thanks !


If you just want it there instantly, you'd just call SetTop and SetLeft again. Otherwise you'd use a StoryBoard, probably with 2 DoubleAnimationUsingKeyFrames elements that specify the Top and Left properties should change from 150/80 to 100/100 over your desired period of time (1 key frame for the initial value, 1 key frame for the final value).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜