Why is there a black lag every time a WPF window is resized?
Asked Answered
S

2

7

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

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:

WPF window being resized

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.

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

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

Sturgeon answered 11/4, 2014 at 13:53 Comment(14)
I don't believe (but I'm not sure) that there is a real fix for this that we can implement. Just open up Microsoft Word/Excel/Outlook and resize the application and you'll experience nearly the same issues that you are experiencing. There ARE ways to help reduce the noticeability (found here) but if Microsoft can't get their own software around the issue then I don't think we'll be able to, either.Montane
Word, Excel and Outlook resize extremely well on my system with no black at all. Visual Studio and Blend, however, do not. The tool windows do.Sturgeon
I wonder what is causing it?Sturgeon
Interesting problem I certainly do not have it on XP and Win7. We are running mainly series 7 AMD cards. Have you tried forcing software rendering to see what happens? In application start up try RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly.Tishtisha
have you tried updating your GPU drivers?Coequal
I don't see this behavior with an empty WPF window. I do see it with crowded WPF Windows, and with Excel I see a little bit of it in certain areas.Clerical
@Sturgeon I'm pretty sure they used the method found in that link I left there - in short, they change the default colour that would be shown (black) to a colour of their choice (grey/black/white... depending on the theme) so that it isn't as obvious. The problem is very well there for their products, though, no doubt.Montane
@Tishtisha That helps slightly. SoftwareOnly is about half as slow. I am very interested to know that it works for you.Sturgeon
@XAMIMAX Yes, even tried beta.Sturgeon
@AndrewMack I do believe you are right.Sturgeon
I have had problems with ATI cards on WPF before but this is mainly on XP. Our computers running nvidia cards have never had problems with WPF. I solved all problems on ATI cards by forcing software rendering. We have around 150 computers and it only happened on about 3. Have you tried another computer or different graphics card just to rule hardware out?Tishtisha
@Tishtisha Everyone has the same hardware here, recent upgrades. I have a Geforce GTX 650 Ti at home. I'll let you know.Sturgeon
I would give it a test at home to see if the same happens on your card. Our main data capture UI has lots of controls (50-100) and there is no blackness on XP or 7 when resizing.Tishtisha
The GeForce is doing the exact same thing. I suppose no combination of settings helps alleviate this?Sturgeon
A
3

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.

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.

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.

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.

Ambry answered 11/4, 2014 at 21:57 Comment(0)
B
1

The look is crummy indeed, especially when using the top or left border.

Which exact problem your screen shot is showing depends on how long your app is taking to render as well as a couple of background related settings that you might be able to tweak to get better resize. Plus part of the ugly resize is specific to Aero.

While I can't address the specific crazy slowness of WPF redraw, I can at least give some insight on why you see black, where that is coming from, and whether you can change to a less annoying fill-in color.

It turns out there are multiple different sources of the black and the bad resize behavior from different Windows versions that combine together. Please see this Q&A which explains what is going on and provides advice for what to do (again, not specific to making WPF faster but just seeing what you can do given the speed you have):

How to smooth ugly jitter/flicker/jumping when resizing windows, especially dragging left/top border (Win 7-10; bg, bitblt and DWM)?

Bryner answered 26/10, 2018 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.