wpf XAML 故事板动画从外部视口-windows phone 8 移动图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19047295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:44:32  来源:igfitidea点击:

XAML storyboard animation moving images from outside viewport-windows phone 8

c#wpfxamlwindows-phone-8

提问by Prasanna Aarthi

I need to create a splash screen, where image needs to slide from bottom of the screen up.Initially it should be placed outside the viewport and then brought in.I understand i need to use story board animation,give target property as image's name and use render translate.Since m new to XAML.. I have the bare skeleton, I dunno how to build things up from here.. please help.

我需要创建一个闪屏,其中图像需要从屏幕底部向上滑动。最初它应该放在视口之外然后被引入。我知道我需要使用故事板动画,将目标属性作为图像的名称和使用渲染翻译。因为我是 XAML 的新手.. 我有裸机,我不知道如何从这里构建东西.. 请帮忙。

  <Grid HorizontalAlignment="Left" Height="1047" VerticalAlignment="Top" Width="480" Margin="0,-24,0,-255" Background="White">
    <Grid.Resources>
        <Storyboard x:Name="myanimation">
            <DoubleAnimation></DoubleAnimation>
        </Storyboard>
    </Grid.Resources>
    <Image HorizontalAlignment="Left" Height="252" Margin="0,795,0,0" VerticalAlignment="Top" Width="480" Source="/Assets/splash-bottom.png"/>
</Grid>

回答by ZombieSheep

The easiest way to do this is the add a CompositeTransform to your image, initially set off the screen, and then animate the TranslateY property.

最简单的方法是将 CompositeTransform 添加到您的图像,最初设置在屏幕上,然后为 TranslateY 属性设置动画。

<Grid ...>
    <Grid.Resources>
        <Storyboard x:Name="MainImageSlideIn">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="MainImage">
                <EasingDoubleKeyFrame KeyTime="0" Value="900"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="0" />
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
    </Grid.Resources>
    <Image x:Name="MainImage"HorizontalAlignment="Left" VerticalAlignment="Top" Width="480" Source="/Assets/splash-bottom.png">
        <Image.RenderTransform>
            <CompositeTransform TranslateY="900" />
        </Image.RenderTransform>
    </Image>
</Grid>

You'll also need to trigger the storyboard to begin. I can't remember the XAML for triggering it as an event, but you can add MainImageSlideIn.Begin() in your page's Loadedevent in C#

您还需要触发故事板才能开始。我不记得将其作为事件触发的 XAML,但您可以Loaded在 C# 的页面事件中添加 MainImageSlideIn.Begin()