开发者

Immediate update in silverlight

Whenever I update contents of a label from inside a loop, the changes are no instantly replicated but only the final value comes up in the end. How can I force it to r开发者_运维知识库eplicate the changes instantly?

for(int i=0; i<5; i++) { 
   label1.Content = x[i];
   Thread.sleep(100);
}

I want it to change the label value five times while waiting for 100 ms in between.


If you're doing this on the main UI thread (which you are unless you've started your own thread) the thread won't be free to update the UI until after your loop is finished. Use a DispatcherTimer instead and register a handler for the Tick event and update the label in the event handler. That way you won't lock up the UI thread for the duration of the loop (which you are doing when you are calling Thread.Sleep).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜