问题
changing the text of a label (or sophisticatedly we can say a text-based progress bar). in winforms you just Invalidate / Update.
But how to do this in WPF without using Background Threads. ???
回答1:
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
回答2:
Perhaps you should read more on the subject of Bindings..
Basicly, bindings will manage this for you..
来源:https://stackoverflow.com/questions/1831373/refresh-update-wpf-controls-like-win-forms