试图在连续动画中保留五组图像(png格式)

时间:2016-12-21 09:35:44

标签: c# xaml uwp

我试图在连续动画中保留五组图像(png格式),这应该占据全屏,点击该弹出窗口后它应该会消失。 有不同位置的相同图像,感觉它不断上下移动。在下面的代码中,我只使用了一个图像" good_job.png"作为弹出窗口。但是如何使用五个不同的图像来上下显示运动。任何帮助将不胜感激。

的Xaml

<RelativePanel x:Name="contentPanel" Grid.Row="1">
    <Canvas RelativePanel.AlignTopWithPanel="True">
                    <Popup x:Name ="ppup" IsOpen = "False" IsLightDismissEnabled   = "True"
                           Width="420"  VerticalAlignment="Top"
                           >
                        <Image Source = "Assets/good_job.png" Canvas.ZIndex="1" Width="420"  />
                    </Popup>
                    <Popup x:Name ="ppup1" IsOpen = "False" IsLightDismissEnabled = "True"  
                           Width="320"  VerticalAlignment="Center">
                        <Image Source = "Assets/wrong_ans.png" Canvas.ZIndex="1" Width="420" />
                    </Popup>
                </Canvas>
</RelativePanel>
<Image x:Name="image1" Source="Assets/LearnColor/Object/ob_0_0.png" Height="150" Width="160" RelativePanel.AlignLeftWithPanel="True" Margin="30,40,0,0" Tapped="image1Tap" d:LayoutOverrides="Width, LeftMargin,                           RightMargin" />

C#代码

if ((image1.Source as BitmapImage).UriSource == new Uri("ms-appx:///Assets/LearnColor/Object/ob_0_0.png", UriKind.Absolute) && (objNameWritten1.Text == "Banana")) 
{
    ppup.Height = Window.Current.Bounds.Height;
    ppup.IsOpen = true;
    mediaElement1.Source = new Uri("ms-appx:///Audio/wow good job.mp3");
    mediaElement1.AutoPlay = true;

}

1 个答案:

答案 0 :(得分:0)

注意:此答案未经测试,很快就会被抛到一起。我提交了它是因为我在评论中被问到了。

首先创建一种循环图像的方法。

private int CurrentImageId = 0;
private List<string> Images = new List<string>() { "image1", "image2", "image3", "image4", "image5" };

private string NextImage() {
    CurrentImageId = (CurrentImageId + 1) % 5;
    return Images[CurrentImageId];
}

然后使用计时器以一定间隔重新设置ImageSource

var timer = new Timer(100);
timer.Elapsed += (sender, args) => Images.ImageSource = NextImage();
timer.Start();