Maximizing borderless window using SysParameter values
Earlier on, I had written a post on maximizing a borderless (WindowStyle=None) window but without covering the taskbar. This solution works well but was not that nice to look at implementation wise :) ... However, theres a simplere solution to achieve the same. I get quite a few queries about the previous post, so I thought it would be a good idea to post this simple solution..
<Window
Width="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenWidthKey}}"
Height="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}"
WindowStartupLocation="CenterScreen"
WindowStyle="None"/>
SystemParameters to the rescue... for the code behind version,
win.Height = SystemParameters.MaximizedPrimaryScreenHeight;
win.Width = SystemParameters.MaximizedPrimaryScreenWidth;
win.Top = 0;win.Left = 0;
Comments
Anonymous
February 07, 2008
PingBack from http://msdnrss.thecoderblogs.com/2008/02/07/maximizing-borderless-window-using-sysparameter-values/Anonymous
February 07, 2008
Presumably this only works if you maximize the window on the primary screen. Maximizing it on any other screen would have incorrect results.Anonymous
February 07, 2008
thats true... on multiple screens, the first solution is likely to work :)Anonymous
February 07, 2008
You've been kicked (a good thing) - Trackback from DotNetKicks.comAnonymous
February 14, 2008
This only works for the secondary screen when both screens have the same resolution! If the resolution is diffrent on secondary screen the window is sized be the width & height of the primery screen. I didnt found a solution to get the resolution (Width & Height)of the secondary screen.Anonymous
March 18, 2008
In your original post, there was an issue where the window wouldn't obey the minimum size when resizing. It would cut off the right and bottom of the window. When I originally implemented a fix for this, it worked, but not for DPI settings larger than 96 (it would use the minTrackSize, but due to the difference in the way WPF and the MonitorInfo.ptMinTrackSize work, the minTrackSizewould not be accurate with larger DPI settings. To fix this, Add two private class variables: float desktopDpiX = 96f; float desktopDpiY = 96f; then, at the bottom of the SourceInitialized event, add: System.Drawing.Graphics desktop = System.Drawing.Graphics.FromHwnd(handle); desktopDpiX = desktop.DpiX; desktopDpiY = desktop.DpiY; finally, in the WmGetMinMaxInfo function, after: mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top); add: mmi.ptMinTrackSize.x = Convert.ToInt16(this.MinWidth * (desktopDpiX / 96)); mmi.ptMinTrackSize.y = Convert.ToInt16(this.MinHeight * (desktopDpiY / 96)); This should fix the resizing issue and accurately adjust the minTrackSize based on the DPI settings. I hope this helps others with the same issue, John Rennemeyer MuvEnum