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

PreferredMinMaxWidthHeight APIs don't handle different DPIs well

Open niels9001 opened this issue 1 year ago • 4 comments

Describe the bug

When the minimum size is set on a window, using the new APIs shipping with 1.7, and a window gets moved to another screen the window size does not get adjusted.

Steps to reproduce the bug

My setup: Screen 1: 1920x1080 (100%) Screen 2: 2048x1152 (150%)

  1. Create a new WinUI app using 1.7-stable
  2. Add the following code to MainWindow.xaml.cs:
OverlappedPresenter presenter = OverlappedPresenter.Create();
presenter.PreferredMinimumWidth = 800;
presenter.PreferredMinimumHeight = 800;
this.AppWindow.SetPresenter(presenter);
  1. Press F5
  2. Minimize the window
  3. Use Win+Shift+Arrows to move the window around
  4. Window can be resized again on the screen with the larger DPI.

The first window shows the bug. The second window (AI Dev Gallery) uses WinUIEx and is rendering as expected. Image

Expected behavior

The window should render properly. See the second part of the gif above for the expected result (the AI Dev Gallery window)

Screenshots

No response

NuGet package version

Windows App SDK 1.7.0: 1.7.250310001

Packaging type

Packaged (MSIX)

Windows version

Windows 11 version 24H2 (22621, October 2024 Update)

IDE

Visual Studio 2022-preview

Additional context

No response

niels9001 avatar Mar 19 '25 10:03 niels9001

3rd party devs can create 3rd party libs that works as expected. (WinUIEx).

what a load of clusterf**k MS' WinUI3 devs are! what a shame!

ref: https://github.com/microsoft/WindowsAppSDK/discussions/5250

mominshaikhdevs avatar Mar 19 '25 11:03 mominshaikhdevs

@niels9001 This is due to the fact that, like other sizing-related AppWindow APIs, PreferredMinMaxWidthHeight work with screen coordinates. I can see the argument to diverge from that convention, though, or at least only make it matter when setting the properties, since the window is resized to match DPI when dragged to a different monitor.

daamenik avatar Mar 24 '25 16:03 daamenik

I'm removing my duplicated issue, I'll follow needed solution here.

LucaCris avatar Mar 29 '25 11:03 LucaCris

@niels9001 This is due to the fact that, like other sizing-related AppWindow APIs, PreferredMinMaxWidthHeight work with screen coordinates. I can see the argument to diverge from that convention, though, or at least only make it matter when setting the properties, since the window is resized to match DPI when dragged to a different monitor.

It makes absolutely no sense to not adjust these values when moving between displays with different DPIs. The values set for PreferredMinMaxWidthHeight have to be interpreted as 100% (GetDpiForWindow(hwnd) / 96F = 1) so it auto-adjusts when the display the windows is moved to has differing DPI.

If the framework does not do this by itself, then the developer has to intercept WM_DPICHANGED and adjust the values for PreferredMinMaxWidthHeight on every change.

And if you force me to do this, then im keeping my current solution of intercepting WM_GETMINMAXINFO and relying on my own solution, because i know that it works the way it should.

Honestly i am questioning, if the developer implementing this feature, ever tried it on multiple monitors with different DPIs. And if he did, what was the motivation to keep it this way.

Balkoth avatar Jun 02 '25 09:06 Balkoth