<Page.Resources>
<Storyboard x:Name="Storyboard1">
<DoubleAnimationUsingKeyFrames x:Name="TranslateX" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="imageToAnimate">
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames x:Name="TranslateY" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="imageToAnimate">
</DoubleAnimationUsingKeyFrames>
</Storyboard>
</Page.Resources>
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Image x:Name="imageToAnimate" Source="/Assets/Logo.png" Width="150" Height="150" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<CompositeTransform/>
</Image.RenderTransform></Image>
</Grid>
在代码中,您可以设置要翻译的点
EasingDoubleKeyFrame animateX1 = new EasingDoubleKeyFrame();
animateX1.KeyTime = new TimeSpan(0);
animateX1.Value = 1;
EasingDoubleKeyFrame animateX2 = new EasingDoubleKeyFrame();
animateX2.KeyTime = new TimeSpan(0, 0, 2);
animateX2.Value = 250;
EasingDoubleKeyFrame animateY1 = new EasingDoubleKeyFrame();
animateY1.KeyTime = new TimeSpan(0);
animateY1.Value = 1;
EasingDoubleKeyFrame animateY2 = new EasingDoubleKeyFrame();
animateY2.KeyTime = new TimeSpan(0, 0, 2);
animateY2.Value = 250;
TranslateX.KeyFrames.Add(animateX1);
TranslateX.KeyFrames.Add(animateX2);
TranslateY.KeyFrames.Add(animateY1);
TranslateY.KeyFrames.Add(animateY2);
Storyboard1.Begin();