Welcome to MSDN Blogs Sign in | Join | Help

Lester's WPF blog


Simple, easy & beautiful
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;

 

Share this post

 

Posted: Thursday, February 07, 2008 7:06 PM by llester

Comments

divil said:

Presumably this only works if you maximize the window on the primary screen. Maximizing it on any other screen would have incorrect results.

# February 7, 2008 3:48 PM

llester said:

thats true... on multiple screens, the first solution is likely to work :)

# February 7, 2008 8:22 PM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# February 7, 2008 8:22 PM

Felix said:

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.

# February 14, 2008 6:50 PM

John said:

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

# March 18, 2008 11:50 AM
New Comments to this post are disabled
Page view tracker