开发者

Refresh / Update WPF controls like win forms

changing the text of a label (or sophisticatedly we can say a text-based progress bar). in winforms you just 开发者_如何学CInvalidate / Update.

But how to do this in WPF without using Background Threads. ???


    public static class ExtensionMethods
{

   private static Action EmptyDelegate = delegate() { };


   public static void Refresh(this UIElement uiElement)
   {
      uiElement.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
   }
}

private void LoopingMethod()
{
   for (int i = 0; i < 10; i++)
   {
      label1.Content = i.ToString();
      label1.Refresh();
      Thread.Sleep(500);
   }
}

Reference: http://geekswithblogs.net/NewThingsILearned/archive/2008/08/25/refresh--update-wpf-controls.aspx


Perhaps you should read more on the subject of Bindings..

Basicly, bindings will manage this for you..

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜