我从服务器获取的图片,每张图片有自己的显示时间,我用的DispatcherTimer去实现,但是只显示最后一张图片,代码如下,求帮助
for (int i = 0; i < result.Length; i++)
{
int duration = Convert.ToInt32(array[4].Trim());
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(2000);
timer.Start();
timer.Tick += timer_Tick;[/align]
}
void timer_Tick(object sender, EventArgs e)
{
imgAdvertisement.Source = new BitmapImage(new Uri(("http://192.168.10.110/advert/" + adPic), UriKind.Absolute));
}
windows?phone?8
------解决方案--------------------
测试一下从 URL 下载图片需要多少时间?是不是延时不够呢。
------解决方案--------------------
记录时间戳
------解决方案--------------------
我都没有试过啊 你试试
------解决方案--------------------
从你的代码看,你为每个图片建了一个timer,每个timer的启动时间和间隔时间都是一样的,怎么可能有动画效果。
------------------
欢迎大家访问我的blog:http://blogs.msdn.com/b/hanxia
------解决方案--------------------
这个基本的逻辑是有问题的呀,for (int i = 0; i < result.Length; i++)
{
int duration = Convert.ToInt32(array[4].Trim());
DispatcherTimer timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromSeconds(2000);
timer.Start();
timer.Tick += timer_Tick;[/align]
}
这个是每次都NEW出来一个TIMER,应该是只有timer.Interval = TimeSpan.FromSeconds(2000);
timer.Start();
timer.Tick += timer_Tick;[/align]
把FOR去掉就对了
------解决方案--------------------
你timer的duration根本就没有用到,而且for循环里的duration的取值是数组中第四个书,怎么表现出不同来?
------------------
欢迎大家访问我的blog:http://blogs.msdn.com/b/hanxia