刷新/更新 WPF 控件,如 win 表单 [英] Refresh / Update WPF controls like win forms
本文介绍了刷新/更新 WPF 控件,如 win 表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
更改标签的文本(或者更复杂的我们可以说是基于文本的进度条).在 winforms 中,您只是无效/更新.
changing the text of a label (or sophisticatedly we can say a text-based progress bar). in winforms you just Invalidate / Update.
但是如何在不使用后台线程的情况下在 WPF 中执行此操作.???
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);
}
}
参考:http://geekswithblogs.net/NewThingsILearned/archive/2008/08/25/refresh--update-wpf-controls.aspx
这篇关于刷新/更新 WPF 控件,如 win 表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文