-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Fixed Incorrect Window.Y and Window.Height values when closing a maximized window #29253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Hey there @@Dhivya-SF4094! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
int cbAttribute); | ||
|
||
internal static Rect GetExtendedFrameBounds(this IntPtr hwnd) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can check hwnd
to avoid unnecessary calls with invalid handles.
if (hwnd == IntPtr.Zero)
{
return Rect.Zero;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz Added a check to avoid unnecessary calls.
|
||
internal static Rect GetExtendedFrameBounds(this IntPtr hwnd) | ||
{ | ||
if (DwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, out PlatformMethods.RECT rect, Marshal.SizeOf<PlatformMethods.RECT>()) == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we wrapped in a try-catch and return an empty Rect if there are any exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz Wrapped the logic in a try-catch block to return an empty Rect in case of exceptions.
var size = appWindow.Size; | ||
var pos = appWindow.Position; | ||
var hwnd = PlatformView.GetWindowHandle(); | ||
var bounds = hwnd.GetExtendedFrameBounds(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would include a check to validate that the return Rect is empty, in that case we need a fallback, like:
var size = appWindow.Size;
var pos = appWindow.Position;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz Added fallback to use appWindow.Position and appWindow.Size when Rect is empty.
/azp run MAUI-UITests-public |
Azure Pipelines successfully started running 1 pipeline(s). |
Issue Detail:
On the Windows platform, if the application window is maximized, the main window X,Y values are in negative (-7, -7). For a non-maximized window, values are correct.
Root Cause
On Windows, when the application window is maximized, the values of Window.Y and Window.Height reported during Window_Destroying are offset by 8 pixels. This occurs because the default window bounds include the non-client area (e.g., title bar and borders), which is excluded by the OS when maximizing the window. As a result, the bounds do not accurately reflect the actual client area used by the application, leading to incorrect frame values being reported to the virtual view.
Description of Change
The issue is resolved by using the Desktop Window Manager (DWM) API to retrieve the extended frame bounds of the window, which represent the true screen-space rectangle of the client area, even when the window is maximized. This is done via DwmGetWindowAttribute with the DWMWA_EXTENDED_FRAME_BOUNDS attribute. The retrieved bounds are then normalized by the display density and used to update the virtual view frame, ensuring accurate X, Y, Width, and Height values.
Validated the behaviour in the following platforms
Issues Fixed:
Fixes #29066
Screenshots