how can I set a minimum size in an universal app (win 10) for the application window? in my project I have only object with Page tag, not Window. I want that the screen of the application can't be resized less off a certein value.
thanks a lot
In the Package.appxmanifest of a Windows 8.1 Universal app, you could set a minimum width, to one of 3 pre-defined values. Setting minimum values on your page will not prevent your application from resizing. Setting maximum values will not prevent resizing either, but it will result in black borders when the application frame is larger than your set dimension. It's worth mentioning that 320 px is the absolute minimum width on 8.1 and on Windows 10 (for phones).
In Windows 10 UWP this property is no longer available. You should AdaptiveTriggers to handle your UI layout on Windows 10.
If you want to check the minimum resize dimensions, keep the scaling of your pc in mind. My laptop scales at 125%, a screenshot of the minimum dimension for the desktop client is 627x441 (~500x350 at 100%) including the space used for the app bar. But it's more common to just use AdaptiveTrigger and 720 pixels as the cut-off between phone and tablet.
you are working on a universal app, you shouldn't set a minimum width . It should be working on every resolution and device.
you should instead use visual state manager and adaptive triggers.
best of luck !
I came across this question in 2023, for WinUI 3 XAML.
If you can get access to the WndProc (which you can in WinUI 3 [and probably WPF], but not UWP), you can use that to set a minimum size for your app.
The recommended solution, implemented on GitHub, is to use P/Invoke to call the window subclassing functions
SetWindowSubclass
andDefSubclassProc
:
- Write a static WndProc method that handles
WM_GETMINMAXINFO
, then forwards any other window messages to the original WndProc, viaDefSubclassProc
(orCallWindowProc
in the examples), although note the disadvantages).- Register your new WndProc via
SetWindowSubclass
(orSetWindowLongPtr
in the examples).This comes from an issue on the XAML GitHub repo.
See WinUI 3 How to set Minimum Size of a Window and WM_GETMINMAXINFO in WinUI 3 with C#?