microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

AppWindow sizing on zoomed screen

Open LucaCris opened this issue 3 years ago • 3 comments

Describe the bug

If a Windows screen is not at 100% zoom, MoveAndResize has unexpected behavior.

Steps to reproduce the bug

Place a WinUI-3 window (wrapped on new AppWindow) on a screen with resolution different from 100%, ie: 150%.

Read its size via AppWindow.Size property. For example the result is 800x600.

Set 800x600 as rect size in AppWindow.MoveAndResize()

The window is now bigger.

Re-read size: the result is 1200x900 (150% of expected).

Expected behavior

Scaling both get and set or never scale size.

Screenshots

No response

NuGet package version

1.1.1

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 21H2 (22000)

IDE

Visual Studio 2022

Additional context

High severity for Apps that must save last window position (also for extra app windows).

LucaCris avatar Jul 04 '22 15:07 LucaCris

I also encountered this bug.

I think

myAppWindow.MoveAndResize({x, y, w, h});

should function the same as

myAppWindow.Move({x, y});
myAppWindow.Resize({w, h});

thus

myAppWindow.MoveAndResize({x, y, w, h});
// Retrieve the window position and size immediately after calling MoveAndResize.
const auto pos = myAppWindow.Position();
const auto size = myAppWindow.Size();
// You would expect the following assert to be true. 
assert(pos.X == x && pos.Y == y && size.Width == w && size.Height == h);

However, AppWindow.MoveAndResize currently behaves more like ResizeAndMove. DPI differences between monitors can cause the window size to change while moving.

nynauy avatar Mar 02 '24 14:03 nynauy

Just encountered this issue. AppWindow.MoveAndResize() is supposedly NOT consider dpi since Move() and Resize() does not consider dpi. I have a window that should be centered on different dpi screens, and when I use MoveAndResize() it gives a wrong size (seems like it uses the dpi on a previous screen). And if I call it a second time with exactly the same parameter, it produce a correct size. I made a simple repro here. A easy workaround is simply use the good-ol win32 SetWindowPos

HO-COOH avatar May 27 '25 15:05 HO-COOH

I also encountered this bug.

I think

myAppWindow.MoveAndResize({x, y, w, h});

should function the same as

myAppWindow.Move({x, y});
myAppWindow.Resize({w, h});

thus

myAppWindow.MoveAndResize({x, y, w, h});
// Retrieve the window position and size immediately after calling MoveAndResize.
const auto pos = myAppWindow.Position();
const auto size = myAppWindow.Size();
// You would expect the following assert to be true. 
assert(pos.X == x && pos.Y == y && size.Width == w && size.Height == h);

However, AppWindow.MoveAndResize currently behaves more like ResizeAndMove. DPI differences between monitors can cause the window size to change while moving.

This description matches our own analysis using multiple screens with varying dpi and scales. This workaround works! The MoveAndResize issue is still present in WinAppSDK Nuget Package Version: 1.7.250606001

cmorschel avatar Oct 31 '25 09:10 cmorschel