0

按照我能找到的唯一文档,我尝试了以下 XAML:

<Image Name="testImage" Source="https://upload.wikimedia.org/wikipedia/commons/c/c4/PM5544_with_non-PAL_signals.png" Width="800">
    <animations:Implicit.Animations>
        <animations:ScalarAnimation Target="Translation.Y" ImplicitTarget="Offset" Duration="0:0:4"/>
        <animations:ScalerAnimation Target="Opacity" Duration="0:0:4" />
    </animations:Implicit.Animations>
</Image>

以下代码有效,不透明度动画并需要 4 秒才能淡出:

private void myButton_Tapped(object sender, TappedRoutedEventArgs e)
{
    testImage.Opacity = 0.2;
}

但我不知道如何触发平移动画(或旋转或缩放)。我试过这个:

private void myButton_Tapped(object sender, TappedRoutedEventArgs e)
{
    var translate = new TranslateTransform();
    translate.Y = 400;
    testImage.RenderTransform = translate;
}

这也希望隐式会覆盖持续时间但没有运气:

private void myButton_Tapped(object sender, TappedRoutedEventArgs e)
{
    testImage.Offset(0, 400, 0).Start();
}

更改应用于这些,但没有 4 秒动画。

4

1 回答 1

2

TranslateTransform是一个并且与您要实现RenderTransform的转换无关,并且隐式动画会覆盖 XAML 设置。CompositionOffset

要使其工作,您需要掌握ElementVisual然后Offset直接更改:

private void myButton_Tapped( object sender, TappedRoutedEventArgs e )
{
    var imageVisual = ElementCompositionPreview.GetElementVisual( testImage );
    imageVisual.Offset = new Vector3( 0, 400, 0 );
}
于 2018-02-16T13:33:21.323 回答