Skip to content

Incorrect Window.X and Window.Y values when closing a maximized window #10521

@Dhivya-SF4094

Description

@Dhivya-SF4094

Describe the bug

if the application window is maximized, the main window X andY values results in -11, -11 when the Window_Destroying(). For a non-maximized window, values are correct.

public partial class App : Application
{

	private void M_window_Closed(object sender, WindowEventArgs args)
	{
		var window = sender as Window;
		// Get HWND
		var hwnd = WindowNative.GetWindowHandle(window);

		// Get WindowId
		var windowId = Win32Interop.GetWindowIdFromWindow(hwnd);

		// Get AppWindow
		var appWindow = AppWindow.GetFromWindowId(windowId);

		// Get position and size
		PointInt32 position = appWindow.Position;
		SizeInt32 size = appWindow.Size;

		int x = position.X;
		int y = position.Y;
		int width = size.Width;
		int height = size.Height;

		Debug.WriteLine($"Window X:{x}, Y:{y}, Width:{width}, Height:{height}");
	}
}

Steps to reproduce the bug

  1. Run the attached sample.
  2. Maximize application window and close window.
  3. Observe the output results in X = -11, Y = -11, Width = 1942 and Height = 1030.

IssueRepo.zip

Expected behavior

No response

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.7.1: 1.7.250401001

Windows version

Windows 11 (23H2): Build 22631

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions