为什么每次调整 WPF 窗口大小时都会出现黑色延迟? [英] Why is there a black lag every time a WPF window is resized?

查看:50
本文介绍了为什么每次调整 WPF 窗口大小时都会出现黑色延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于 SE 的其他问题解决了如何加速嵌套 UI 控件调整大小,但是 - 如果没有任何控件怎么办?

Other questions on SE address how to speed up nested UI control resizing, but- what if there aren't any controls?

当您拖动 WPF 窗口的边缘时,即使是没有内容的主窗口,在拖动过程中黑条也会短暂闪烁.这会产生一种糟糕的感觉——我不想给客户带来这种感觉:

As you drag the edge of a WPF window, even a main window with no content, black bars flicker briefly during the drag. This produces a crummy feel- one that I don't want to inflict on customers:

它确实变得越来越慢,而且在它上面有一个完整的用户界面.这甚至没有涉及使用顶部或左侧边缘调整大小时的外观.Windows 窗体 - 即使使用我构建的最繁重的 UI - 从一开始就看起来从未如此糟糕.

It does get slower and heavier with a full UI on top of it as well. This doesn't even get into how ugly it looks when resizing using the top or left edges. Windows Forms- even with the heaviest UI I've built- never looks this bad right off the bat.

如何才能使 WPF 窗口大小调整性能与 win 窗体相媲美?

What can be done to make WPF window resizing performance comparable to win forms?

(我在 AT Radeon HD 7470 上有 Windows 7 x64 和三显示器系统.)

(I have Windows 7 x64 and a triple monitor system on an AT Radeon HD 7470.)

推荐答案

您可以更新图形卡并再次尝试,但这不会改变任何内容.原因很简单.我们有时会根据我们的计算机的速度/速度来看到这一点.有时它运行流畅,因为我们没有很多视觉效果要绘制.原因是当时在重绘过程​​中没有在图形卡中找到合适的背景颜色.您的驱动程序很好,这不仅仅是因为您使用 Wpf.其他技术在重绘背后使用相同的机制.

You could update your graphic card and try it out again but that wont change anything. The reason is pretty simple. We all get to see this sometimes based how fast/slow our computer is. Sometimes it runs smooth because we do not have many visuals to draw. The reason is no proper background color is found in graphic card at that moment in redrawing process. Your drivers are fine, and its not just because you use Wpf. Other techniques use the same mechanism behind redrawing.

WPF 要做的第一件事就是清除将要重绘的脏区域.脏区的目的是减少发送到 GPU 管道输出合并阶段的像素数量.这是我们看到黑色的地方.此时窗口本身没有背景颜色,或者其背景颜色设置为透明,因此 GPU 绘制黑色背景.事情在 wpf 中异步运行,这很好.

The first thing WPF will do is clear out the dirty region that is going to redraw. The purpose of dirty regions is to reduce the amount of pixels sent to the output merger stage of the GPU pipeline. Here is where we see the black color. Window itself at that point has no background color or its background color is set to transparent and so to us the GPU draws the black background. Things run async in wpf which is good so.

要解决此问题,您可以为窗口设置一个固定颜色,例如白色".然后 WPF 系统将清除脏区域,但会自动用白色而不是黑色填充它.这通常会有所帮助.

To fix this you could set a fix color such as "White" to the Window. Then the WPF system will clean out the dirty region but fill it automatically with white color instead of black. This usually helps.

匹配窗口颜色或最顶层的颜色.不要让 GPU 使用黑色,你应该做得很好.顺便说一句,Wpf 比 WinForm 快,所以不用担心.

Match the window color or the color of top most layer. Dont let GPU use black and you should do fine. Btw Wpf is faster than WinForm so dont worry.

这篇关于为什么每次调整 WPF 窗口大小时都会出现黑色延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆