I have a WPF window located at the top left corner of my primary (and only) screen. I want to translate the point (0,0) in the window to screen coordinates. I believe the following two calls should give me the same result:
1. This results in (8,8)...
window.PointToScreen(new Point(0,0));
2. This results in (0,0)...
PresentationSource.FromVisual(window).CompositionTarget.TransformToDevice.Transform(new Point(0,0));
Why?
The 8 pixel difference suggests that the first call considers the window coordinate system to start AFTER the border, while the second considers the window as a whole, including the non client area (resizing borders & toolbar). Is that true?
(edited to remove superfluous detail about DPI settings)
You know about client area, right?
First call is useful if you want to find out location of child, put into position (0,0) of window, it will be a point inside client region. Window border (to not mix up with Border
) is not client region.
The second call, as I see it, is coordinates of window itself (including border).