Why is 1920 device-independent units not 1920 pixel with 96 DPI? Why is 1920 device-independent units not 1920 pixel with 96 DPI? wpf wpf

Why is 1920 device-independent units not 1920 pixel with 96 DPI?


The question is more along the lines of:

Why does Window.ActualWidth report a width that does not appear to be the 'real' width of the Window?

The answer is that what looks like the full width of the window isn't exactly the full width.

When you set the Width, query the ActualWidth, or even use GetWindowRect to get the "no-lies what does windows think my width is", you're setting or getting the width of the Window including invisible parts.

Those invisible parts, especially on Windows 10, includes a little bit of extra space for making it easy for users to resize the window even if they're a little bit off of the border:

resize off of the window

(note that my mouse is not on the border but rather a bit off to the right)

This means that when you maximize your window, your width is still "padded" with that invisible space, and thus your window size will be bigger than your screen size.

How can you retrieve the width of the extra space? GetSystemMetrics with SM_CXSIZEFRAME and SM_CXPADDEDBORDER is your friend here (example includes code from pinvoke.net):

int extraBorderStuff = GetSystemMetrics(SystemMetric.SM_CXSIZEFRAME)                       + GetSystemMetrics(SystemMetric.SM_CXPADDEDBORDER);double realWidthForSure = ActualWidth - borderSize * 2;

If you then maximize your window, you should notice that realWidthForSure should equal your 1920px that you'd expect.


The window really has a width of 1936 pixels!

When a window is maximized, the border around it is cropped. Although it is not visible any more, it is still considered part of the window. In the Aero theme, this border has a width of 8px on each side, hence the 16px extra:

Window chrome in Aero theme

If you switch to the Classic theme, it's only 4px on each side, so your window would be 1928 pixels wide.


What are your screen specs? for e.g. my monitor has pitch = 0.282 mm; which equals to 90.0709... ppi. A 1920 pixels wide window would have actual width of 2,046 units in WPF.

determine your screen's DPI (25.4/pitch if you have pitch in mm)

96/DPI * 1920 => Actual Width