Maximized window hides automatically hiding taskbar
- .NET Core Version: 3.1
- Windows version: 2004 (Build 19041.450)
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
Problem description:
Actual behavior: Taskbar in automatic hide mode does not appear when moving the mouse pointer to the taskbar area in a maximized WPF app window.
Expected behavior: Taskbar should slide open regardless window normal/maximized state.
Minimal repro:
- Set the taskbar to auto hide mode.
- Create a new Visual Studio 2019 project of type WPF App for .NET Framework 4.8 or .NET Core 3.1.
- Run the app.
- Maximize the blank app window and hover the taskbar area. The taskbar will now not be shown.
Findings:
- Expected behavior in a Windows Forms app on .NET Framework 4.8 or .NET Core 3.1.
- Expected behavior in Windows Notepad. (to further exclude any Windows 10 bugs)
- Expected behavior in a dual screen setup when maximizing the window and hovering the taskbar area on the secondary screen.
- The same behavior is seen in Windows 10 Version 1909.
- The behavior does not seem to depend on DPI settings. Tested resolution on two systems in 2560x1440.
@jonasnordlund I assume that you would not want the taskbar to appear when in full screen mode AND with TopMost set, correct? If so, this would interfere with the function of full screen KIOSK style applications. I can definitely see the need in non topmost apps.
I don't mind apps hiding an auto hiding taskbar if their "top most" flag is set and the app is maximized because this looks like the correct behavior. The bug is really only about non-topmost apps doing the same thing and this seems to be a particular behavior in WPF apps and not Win32, Windows Forms, or UWP apps.
@jonasnordlund I would agree with you on that then. This is one of those things that I have never noticed so its a good catch on your part.
Confirming this is still an active issue with the latest .NET 9 release
So, I found a way to fix it, but you need to use some reflection for it..
I was looking at my wpf window in Window Detective, and I tried changing the window styles of my wpf window, and I found that it shows the taskbar if I add the WS_THICKFRAME style to my wpf window, so then I found a way to change the window style for my wpf window in code.
I got my window's current style by getting the value of the private property _Style in the Window class and added the value of WS_THICKFRAME to it, which is 0x00040000, and then called the native method SetWindowLongPtrWrapper in PresentationNative_cor3.dll that I found from the wpf source code, and now my taskbar shows for my wpf window.
Maybe the devs of wpf could find some way to implement this by default for wpf windows.
int style = (int) GetType().GetProperty("_Style", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(this);
style |= 0x00040000;
SetWindowLongPtr(new HandleRef(this, ((HwndSource?) PresentationSource.FromVisual(this)).Handle), (-16), style);
and the native method.
[DllImport("PresentationNative_cor3.dll", EntryPoint = "SetWindowLongPtrWrapper", CharSet = CharSet.Auto)]
private static extern IntPtr SetWindowLongPtr(HandleRef hWnd, int nIndex, IntPtr dwNewLong);