如何使用Windows Phone 8应用程序中的故事板创建5个图像的动画

时间:2014-11-26 11:48:13

标签: windows-phone-8

我需要创建带有两个以上图像的动画。我用两个图像完成动画,如下图所示。我是这个环境的初学者,请帮我创建五个图像的故事板。

  in class i'm calling this method.


  protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        Storyboard1.Begin();  
    }





      <phone:PhoneApplicationPage.Resources>
       <Storyboard x:Name="Storyboard1">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"  Storyboard.TargetName="image2" RepeatBehavior="Forever">
            <DiscreteDoubleKeyFrame KeyTime="0" Value="1"/>
            <DiscreteDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
            <DiscreteDoubleKeyFrame KeyTime="0:0:2" Value="1"/>

        </DoubleAnimationUsingKeyFrames>
    </Storyboard>

   <Grid x:Name="LayoutRoot" Background="Transparent">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>





    <!--ContentPanel - place additional content here-->
    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid.RowDefinitions>

            <RowDefinition Height="230"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">

            <Image  Stretch="Uniform" Name="image1" Source="/Images/w1.png" />
            <Image Stretch="Uniform" Name="image2" Source="/Images/w2.png" />
          <!--  
            <Image  Stretch="Uniform" Name="image3" Source="/Images/w3.png" />
            <Image Stretch="Uniform" Name="image4" Source="/Images/w4.png" />
            <Image Stretch="Uniform" Name="image4" Source="/Images/w5.png" />
           -->

        </Grid>
    </Grid>



     Please Help me.....

1 个答案:

答案 0 :(得分:0)

我猜你只想切换图片?有点像翻书,是吗?

如果是这种情况,动画Opacity是不好的方法。为什么不只是动画Source并将其从w1.png切换到w2.png到w3.png等?

通过这种方式,您可以将代码简化为基本

<Image  Stretch="Uniform" Name="myImage" Source="/Images/w1.png" />

您的StoryBoard

<Storyboard x:Name="Storyboard1">
    <ObjectAnimationUsingKeyFrames  Storyboard.TargetProperty="(Image.Source)"  Storyboard.TargetName="myImage" RepeatBehavior="Forever">
        <DiscreteObjectKeyFrame KeyTime="0" Value="="/Images/w1.png"></DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:1" Value="="/Images/w2.png"></DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:2" Value="="/Images/w3.png"></DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:3" Value="="/Images/w4.png"></DiscreteObjectKeyFrame>
        <DiscreteObjectKeyFrame KeyTime="0:0:4" Value="="/Images/w5.png"></DiscreteObjectKeyFrame>
    </ObjectAnimationUsingKeyFrames>
</Storyboard>

如果你想保留一些奇怪的不透明度动画,你也可以将它们添加到StoryBoard中。