在 C# 中,如何将刷新/重绘消息发送到 WPF 网格或画布?

In C#, how do you send a refresh/repaint message to a WPF grid or canvas?(在 C# 中,如何将刷新/重绘消息发送到 WPF 网格或画布?)
本文介绍了在 C# 中,如何将刷新/重绘消息发送到 WPF 网格或画布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何向 WPF 网格或画布发送刷新消息?

How do you send a refresh message to a WPF grid or canvas?

换句话说,我注意到在调试模式下,我可以编写代码将一行发送到显示器,然后,如果该行不正确,我可以调整它——但前一行仍然存在.现在,我正在编写的代码根据用户点击的内容向显示器发送信息.所以这一定意味着每次新的一组行和框以及文本进入 WPF 中的网格或画布时,都不会刷新显示.

In other words, I have noticed while in debug mode, I can write code that sends a line to the display and then, if that line is not right, I can adjust it -- but the previous line is still there. Now, the code I am writing sends information to the display based on what the user clicks. So this must mean that the display is not refreshed each time a new set of lines and boxes and text goes to the grid or canvas in WPF.

使用 C# 代码,如何将刷新/重绘消息发送到 WPF 网格或画布?

Using C# code, how do you send a refresh/repaint message to a WPF grid or canvas?

推荐答案

刷新更新 Winforms 等 WPF 控件

public static class ExtensionMethods
{
   private static Action EmptyDelegate = delegate() { };

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

这篇关于在 C# 中,如何将刷新/重绘消息发送到 WPF 网格或画布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)