繁体   English   中英

Windows Phone 8上的图像动画

[英]Image Animation on windows phone 8

我创建了一个包含两个图像的列表框

<ListBox x:Name="list1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Margin="0,10,0,-10" RenderTransformOrigin="0.5,0.5" Grid.Row="1">
        <ListBox.RenderTransform>
            <CompositeTransform/>
        </ListBox.RenderTransform>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">

                        <Image Source="{Binding image}"  Stretch="Fill"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

现在如何在两个图像之间交替显示一个永久的动画...如果有更简单的方法,请告知。 我想要一些简单的方法[例如,显示图像A 5秒钟,然后显示图像B 5秒钟,然后重新启动]

如您所说,使用StoryBoard概念非常简单。 首先像这样在网格中添加两个图像,

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
        <Grid Margin="0,24,0,24">
            <Image Name="image1" Source="/Assets/1.jpg" />
            <Image Name="image2" Source="/Assets/2.jpg" />
        </Grid>
    </Grid>

然后在页面的主网格上方添加以下代码。 它应该在PhoneApplicationPage.Resources这样的

<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:5" Value="0"/>
            <DiscreteDoubleKeyFrame KeyTime="0:0:10" Value="1"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</phone:PhoneApplicationPage.Resources>

最后,在.cs文件的OnNavigatedTo中添加以下代码。

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

这样就完成了。

尝试这个

<Page.Resources>
    <ImageBrush x:Key="Imag1" ImageSource="Assets/Logo.png"></ImageBrush>
    <ImageBrush x:Key="Imag2" ImageSource="Assets/Cera.png"></ImageBrush>
</Page.Resources>


<Grid Height="200" Width="200" Background="{StaticResource Imag1}" Name="Gd">
    <Grid.Triggers>
        <EventTrigger>
            <BeginStoryboard>
                <Storyboard>
                    <ObjectAnimationUsingKeyFrames Duration="0:0:2"  RepeatBehavior="Forever" Storyboard.TargetName="Gd" Storyboard.TargetProperty="Background">
                        <DiscreteObjectKeyFrame KeyTime="0:0:1" Value="{StaticResource Imag2}" ></DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Grid.Triggers>
</Grid>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM