Is there a way to reduce or prevent form flickering when using WPF?
Asked Answered
H

1

2

I'm actually having 2 different flickering issues:

(1) When I create a form with border style set to none, anytime I resize the window there is a good amount of flickering along the edges of the form. This is especially noticeable if I try to resize the form from the top left corner.

(2) When I minimize the form and restore it from the taskbar, for a (very) brief second in the top left corner where the title would normally be you can see a rectangle shape flicker. I think this might be normal windows behavior but it has just become more noticeable due to WPF removing the windows minimize/maximize animations. If I can't fix the flickering directly this way, is it possible to restore the min/max animations without using hacky solutions such as setting the bordersize just before the form minimizes?

Thanks for reading!

Highpriced answered 24/1, 2018 at 12:5 Comment(3)
Do you have the desktop window manager running (dwm.exe)? With the Aero composition engine enabled, resizing should be reasonably fluid, but without it, you may see some tearing. There may also be a slight delay between the Win32 layer resizing the window and WPF re-rendering its content (with or without DWM). It's not something you'd be able to fix.Submit
Is there any code or Animation executing as a response to the resizing? (OnSizeChanged, WindowState) those can really slow things downOverfeed
I do have some events but I disabled them as I thought maybe they were causing the problem, but it still happens. I do have dwm running. I know it's probably not possible to have completely smooth resizing of the windows (even visual studio itself doesn't) but I compared this behavior with other programs I have installed and they are significantly smoother. For example, Firefox and Steam both resize smoothly and have no flickering. I know it's not going to be an easy fix because I searched all over before I made this post. Is this a WPF specific issue? Is there a better GUI framework to use?Highpriced
V
0

I was fighting the same issue you mention in #1 and it is not specific to borderless WPF forms (though it appears to be dependent on both draw timing and window styles, both of which may change when you change border types). It happens with native apps and apps with full borders as well.

In Windows 10 you can actually see the same type of flickering in Windows Explorer itself when you use the left and/or top window borders.

From my investigations there appear to be at least two overlapping causes, one that dates from pre-Aero days and one that was added on top by Aero. The pre-Aero cause has a workaround but the Aero one still only has a partial solution. Please see this roundup Question/Answer which brings together 10 years of posts on this topic and offers some new insights (too long to paste the content here in this question). Enjoy:

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

Yes, I know on SO the convention is to mark the original question as a dup rather than linking from one question to another, however this case is a bit unusual. My roundup post refers to more than 30 questions on this topic and brings together the most important ideas from them, but it does not include all the ideas from the original questions...that would be impractical. So I don't actually want to see the original questions marked as dups, nor mine, since either way, useful info would be lost. That is because window resize is a broad topic; this Q covers some aspects, my Q covers others.

Vanadous answered 26/10, 2018 at 9:5 Comment(2)
@Moritz Apology accepted. Thanks a lot; I really appreciate that. I have already modified this answer to include more details relevant to the OP's specific situation with WPF. Currently none of my other answers are identical. I wrote 1-3 sentences on each answer that addresses the specific issue from each question's OP before mentioning the rollup Q/A. However, I think you are right; I need to go to each answer and add more detail to help the specific OPs to make them better answers. I will start to do that now. It will take me a day or two to finish that task, due to day job.Vanadous
Ok I have spent a few hours procrastinating the day job and have added specific, customized advice to each answer including some new code that does not appear in the larger rollup Q&A.Vanadous

© 2022 - 2024 — McMap. All rights reserved.