C# 如何更改图像';在Xamarin.Forms中运行时动态地显示s位置(x和y)?

C# 如何更改图像';在Xamarin.Forms中运行时动态地显示s位置(x和y)?,c#,image,xamarin,xamarin.forms,position,C#,Image,Xamarin,Xamarin.forms,Position,我正在使用Xamarin.Forms,希望动态地(在代码隐藏中)更改图像的位置 我最初是通过在.xaml文件中定义图像来静态加载图像的。然后,我想根据用户的运行时值动态更新图像的位置(水平和垂直)。图像应根据用户输入值移动 不幸的是,我找不到这方面的代码示例 如何动态更改图像的位置(在代码隐藏中)?您可以使用TranslationX和TranslationY属性操纵元素的X和Y坐标 要设置动画,可以使用translate方法: public static System.Threading.Tas

我正在使用Xamarin.Forms,希望动态地(在代码隐藏中)更改图像的位置

我最初是通过在.xaml文件中定义图像来静态加载图像的。然后,我想根据用户的运行时值动态更新图像的位置(水平和垂直)。图像应根据用户输入值移动

不幸的是,我找不到这方面的代码示例


如何动态更改图像的位置(在代码隐藏中)?

您可以使用TranslationX和TranslationY属性操纵元素的X和Y坐标

要设置动画,可以使用translate方法:

public static System.Threading.Tasks.Task<bool> TranslateTo (this Xamarin.Forms.VisualElement view, double x, double y, uint length = 250, Xamarin.Forms.Easing easing = null);
await image.TranslateTo (-100, 0, 1000);    // Move image left
await image.TranslateTo (-100, -100, 1000); // Move image up
await image.TranslateTo (100, 100, 2000);   // Move image diagonally down and right
await image.TranslateTo (0, 100, 1000);     // Move image left
await image.TranslateTo (0, 0, 1000);       // Move image up