更改标签的文本(或者我们可以说是一个复杂的基于文本的进度条)。 在 winforms 中,您只需使/更新无效。
但是如何在不使用后台线程的情况下在 WPF 中执行此操作。 ???
最佳答案
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);
}
}
引用:Link
关于c# - 刷新/更新 WPF 控件,如 winforms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1831373/