我想通过移动动画将汽车移动到点 0、0,但问题是我收到错误然后我使用此功能 - https://gyazo.com/1f47e18f955c12dc1907fcf4d7b19d6a。应用程序外观: https ://gyazo.com/10fb071534809229cb98955f9fb86231 。有我的代码(我在一篇WPF 文章中找到了这个函数。以编程方式将图像移动到 (X,Y) 的最简单方法?):
public void Eiti(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);
}
和 xml:
<DockPanel Grid.Row="1" Background="#FF695887">
<Canvas>
<Image Name="car1" />
</Canvas>
</DockPanel>
如何解决?