2011-12-06 9 views
1

私は離れた記憶装置に保存された画像をスライドショーで表示する必要があります。しかし、私はWindows Phoneで初心者です。私はすでに画像を表示するか、画像を表示する方法を知っています画面で..しかし、私は2秒ごとにイメージを提示したい.. theresいくつかのfuncionaltyは、再現する時間を定義するには?どんな例ですか?スライドショーを作成するwp7

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

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

これは画像を開く方法です。あなたが2秒間現在のスレッドの睡眠を作ることができ

答えて

1

..私はその後、私はそれぞれを開く画像の5名でのforeachを持っている..しかし、私は、画像に2秒を見てみたい:

System.Threading.Thread.Sleep(2000); 

としてforeach体の最後の文。それは非常にきれいではありませんが、それは仕事をするでしょう。

1

より良い方法は、Reactive Extensionです。

まず、このpostで私の答えを見てください。それはあなたに必要なdllと便利なリンクを教えてくれます。

基本的には、コレクションに画像を格納してから、コレクションに基づいて時間ディメンションを持つ観測可能なシーケンスを作成するためにRxGenerateWithTime)を使用する必要があります。最後に、1つの画像を追加し、それを観察可能なシーケンスに登録するメソッドを呼び出します。ここで

一の実施例である、

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); 
} 

は、この情報がお役に立てば幸いです。 :)

関連する問題