刷新/更新 WPF 控件,如 win 表单

发布于 2024-08-13 14:05:04 字数 101 浏览 2 评论 0原文

更改标签的文本(或者复杂地我们可以说是基于文本的进度条)。 在 winforms 中你只需无效/更新。

但是如何在不使用后台线程的情况下在 WPF 中执行此操作。 ???

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. ???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

木有鱼丸 2024-08-20 14:05:04
    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);
   }
}

参考:链接

    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: Link

凡间太子 2024-08-20 14:05:04

也许您应该阅读有关绑定主题的更多内容。

基本上,绑定将为你管理这个..

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

Basicly, bindings will manage this for you..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文