Repository navigation
Description
People have had problems with WindowChrome flickering. In my situation I tracked the bug down to the loop in my code which was changing the window title 3 times a second to "scroll" it like WinAmp.
In WindowChromeWorker._HandleSetTextOrIcon() the WPF framework code plays a trick where it clears WS_VISIBLE before forwarding WM_SETTEXT to DefWindowProc, and then sets it back after returning. The comment says this is done to trick DefWindowProc into not redrawing the caption.
In WindowChromeWorker._UpdateSystemMenu() which is called on every WM_SIZE, the code does the same exact trick with WS_VISIBLE.
This means that every time your window is resized, or the caption is changed, or the window icon is changed, WindowChrome will clear WS_VISIBLE and then reset it.
The problem is that this is the official way to hide and show a window and will not merely behave as a private-data-only change. If the DWM catches the window style change it will hide the window during the DefWindowProc call. Usually it happens fast but it can become a nuisance. This is horrible because if you try to click the window at the wrong time when it is briefly hidden, you will click into emptiness and activate the window underneath it instead. The Windows+Tab virtual desktop switcher is less subtle; every time the WndProc clears WS_VISIBLE for text or icon, the switcher will repeatedly remove the window from the list and add it back, shifting all the other windows around and causing a lot of redraws.
I don't know what the fix should be, but the current situation is unacceptable. Perhaps something could be done like in the _HandleNCActivate() call underneath, which passes an undocumented parameter to DefWindowProc to suppress unwanted behavior. In the meantime I need to phase out all usage of WindowChrome in my code until this is fixed and I advise others to do likewise.
Activity
batzen commentedon Jul 1, 2020
@ClosetBugSlayer you could switch to the WindowChromeBehavior from https://github.com/ControlzEx/ControlzEx
We accept PRs, in case you find the same issues there. 😉
davidbangMicrosoft commentedon Oct 26, 2020
@batzen wondering what the support on ControlzEx will be going forward? I will be using WindowChrome in an app that will probably stay in prod.
davidbangMicrosoft commentedon Oct 26, 2020
@ClosetBugSlayer @batzen does the WindowChromeBehavior have the same issues as WindowChrome when it comes to rendering? It doesn't look like the project changes the underlying issue between races in the DWM, OS and WPF. I am referencing the code here: https://github.com/ControlzEx/ControlzEx/blob/develop/src/ControlzEx/Behaviors/WindowChromeBehavior.cs
batzen commentedon Oct 26, 2020
@davidbangMicrosoft ControlzEx is the building block for Fluent.Ribbon (used in the new WinDbg) and MahApps.Metro. It's actively maintained and supports
net45;net462;netcoreapp3.0;netcoreapp3.1(net50support is currently in a separate branch).The
WindowChromeBehaviordoes, at least, not have as many issues asWindowChromehas (that's the reason why we created it in the first place).Do you have any specific issues in mind regarding rendering?
davidbangMicrosoft commentedon Oct 26, 2020
Great to hear that @batzen . Also yes I have been noticing many issues with WindowChrome when it comes to Window Management etc. Some of these have been resolved privately on the WPF side. Also for the rendering issue, it is similar to what @ClosetBugSlayer mentions in this bug. I haven't investigated as deeply, but seems to be an issue with the Window redrawing on each change such as resize, on load, etc.
davidbangMicrosoft commentedon Oct 26, 2020
@batzen to be honest I wish I had found your project much earlier as I would have likely used it. It is very helpful to look at your fixes though as I can reference them, if you don't mind me reusing privately. Also I am curious why this change hasn't been directly integrated into the WPF project?
batzen commentedon Oct 26, 2020
@davidbangMicrosoft Feel free to reuse the fixes we made.
As this repo (WPF) does not really process PRs as of now and the
WindowChromeBehavioris quite different, in regards to supported features, supported frameworks etc., from theWindowChromein WPF itself porting the fixes does not seem worth the effort to me.Many of the issues we fixed in ControlzEx were reported to Microsoft years ago and, sadly, nothing happened.
Even Visual Studio does not use
WindowChromefrom WPF but a custom solution instead.ClosetBugSlayer commentedon Oct 31, 2020
It looks like WindowChromeBehavior is doing the exact same thing to cause the flicker.
https://github.com/ControlzEx/ControlzEx/blob/develop/src/ControlzEx/Behaviors/WindowChromeBehavior.MessageHandling.cs
`
private IntPtr _HandleSETICONOrSETTEXT(WM uMsg, IntPtr wParam, IntPtr lParam, out bool handled)
{
var modified = this._ModifyStyle(WS.VISIBLE, 0);
`
batzen commentedon Oct 29, 2021
@ClosetBugSlayer FYI: The window chrome from ControlzEx no longer toggles the visible style.
You can try it out by using the changes from ControlzEx/ControlzEx#151
ClosetBugSlayer commentedon Oct 30, 2021
Good deal. Mind summarizing the fix here so the WPF devs can get on it quickly?