当前位置: 代码迷 >> Windows Mobile >> 图片隔一段时间展示
  详细解决方案

图片隔一段时间展示

热度:18   发布时间:2016-04-25 07:16:21.0
图片隔一段时间显示
images.ID 是一个时间的数组,每次循环时间都不一样,达到的效果,就是每张图片在规定的时间内显示?

DispatcherTimer timer = new DispatcherTimer();
            foreach (var images in list)
            {
                timer.Interval = TimeSpan.FromSeconds(images.ID);
                Image img = new Image();
                img.Width = 1350;
                img.Height = 850;
                img.Tag = images.AutoIncrease;
                timer.Tick += (_, __) =>
                    {
                        timer.Stop();
                        string filename = "ms-appx:///Images/" + images.AutoIncrease + ".jpg";
                        img.Source = new BitmapImage(new Uri(filename));
                        sp1.Children.Add(img);
                    };
                timer.Start();
            }

------解决方案--------------------
我想要的效果就是;从服务器去图片和图片对应的时间,然后设定定时器,让每张图片显示对应的时间,然后再显示下一张,但是他不会切换图片 。
------解决方案--------------------

        DispatcherTimer timer = new DispatcherTimer();
        Int32 index = 0;

            timer.Interval = TimeSpan.FromSeconds(0.1);
            timer.Tick += () =>
            {
                timer.Stop();
                if (index>=list.Length)
                {
                    return;
                }
                index++;
                timer.Interval = TimeSpan.FromSeconds(list[index].ID);
                string filename = "ms-appx:///Images/" + list[index].AutoIncrease + ".jpg";
                image.Source = new BitmapImage(new Uri(filename));
                image.Tag = list[index].AutoIncrease;
                timer.Start();
            };



    <Grid Background="Transparent">
        <Image x:Name="image"
               Width="1350"
               Height="850"/>
    </Grid>