make slide show wp7

北慕城南 提交于 2019-12-24 12:01:37

问题


I have to do a slide show off images stored in my isolated storage.. but i am beginner in windows phone and i have some dificulties.. i already know how to present the images, or show the images in the screen.. but i want to present the images 2 seconds each one.. theres some funcionalty to define the time to reproduce? Any example?

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

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

This is how i open the image. I have a foreach with 5 name of images then i open each one.. but i want to see the images 2 seconds..


回答1:


You could make the current thread sleep for 2 seconds:

System.Threading.Thread.Sleep(2000);

As the last sentence in the foreach body. It is not very neat, but it will do the job.




回答2:


A better way is to use Reactive Extension.

First take a look at my answer in this post. It tells you what dlls you will need as well as some useful links.

Basically you need to store you images in a collection and then use Rx (GenerateWithTime) to create a observable sequence with time dimension based on the collection. Finally you call a method to add one image and subscribe it to the observable sequence.

Here is one working example,

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

Hope this helps. :)



来源:https://stackoverflow.com/questions/8408474/make-slide-show-wp7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!