问题描述
如何向 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 网格或画布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!