更新时间:2022-04-11 07:46:31
尝试此代码.
Try this code.
public static void MoveTo(this Image target, double newX, double newY)
{
var top = Canvas.GetTop(target);
var left = Canvas.GetLeft(target);
TranslateTransform trans = new TranslateTransform();
target.RenderTransform = trans;
DoubleAnimation anim1 = new DoubleAnimation(top, newY - top, TimeSpan.FromSeconds(10));
DoubleAnimation anim2 = new DoubleAnimation(left, newX - left, TimeSpan.FromSeconds(10));
trans.BeginAnimation(TranslateTransform.XProperty,anim1);
trans.BeginAnimation(TranslateTransform.YProperty,anim2);
}
Xaml沿路径移动对象.这是链接.
http://blogs.intuidev.com/post/2010/09/14/AnimatingObjectsAlongAPath.aspx [^ ]
Xaml Moving objects along a path. here is the link.
http://blogs.intuidev.com/post/2010/09/14/AnimatingObjectsAlongAPath.aspx[^]