制作幻灯片wp7

时间:2011-12-06 23:37:38

标签: windows-phone-7 timer slide

我必须对存储在我的隔离存储中的图像进行幻灯片放映..但我是Windows手机的初学者,我有一些困难..我已经知道如何呈现图像,或在屏幕上显示图像。但是我希望每张图像呈现2秒......还有一些功能来定义重现的时间吗?任何一个例子?

 IsolatedStorageFileStream stream = new IsolatedStorageFileStream(name_image,       FileMode.Open, myIsolatedStorage);

                    var image = new BitmapImage();
                    image.SetSource(stream);
                    image1.Source = image;

这就是我打开图像的方式。我有一个带有5个图像名称的foreach然后我打开每个..但我想看到图像2秒..

2 个答案:

答案 0 :(得分:1)

您可以让当前线程休眠2秒钟:

System.Threading.Thread.Sleep(2000);

作为foreach身体的最后一句话。它不是很整洁,但它会起作用。

答案 1 :(得分:1)

更好的方法是使用Reactive Extension

首先看看我在post中的答案。它告诉你你需要什么样的dll以及一些有用的链接。

基本上,您需要将图像存储在集合中,然后使用RxGenerateWithTime)根据集合创建具有时间维度的可观察序列。最后,您调用一个方法来添加一个图像并将其订阅到可观察序列。

这是一个有效的例子,

private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    // create a collection to store your 5 images
    var images = new List<Image>
        {
            new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
            new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
            new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
            new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 },
            new Image() { Source = new BitmapImage(new Uri("/ApplicationIcon.png", UriKind.Relative)), Width = 120, Height = 120 }
        };

    // create a time dimension (2 seconds) to the generated sequence
    IObservable<Image> getImages = Observable.GenerateWithTime(0, i => i <= images.Count - 1, i => images[i], _ => TimeSpan.FromSeconds(2), i => ++i);

    // subscribe the DisplayOneImage handler to the sequence
    getImages.ObserveOnDispatcher().Subscribe(DisplayOneImage);
}

private void DisplayOneImage(Image image)
{
    // MyItems is an ItemsControl on the UI
    this.MyItems.Items.Add(image);
}

希望这会有所帮助。 :)