Hebele Hübele
Hebele Hübele

Reputation: 103

WinUI 3 How to set Minimum Size of a Window

So in UWP, we can use

ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(500, 500));

but

ApplicationView.GetForCurrentView();

returns null in WinUI 3. Is there a way to set the minimum size for a window

Upvotes: 4

Views: 2279

Answers (1)

Katana
Katana

Reputation: 1

The recommended solution, implemented on GitHub, is to use P/Invoke to call the window subclassing functions SetWindowSubclass and DefSubclassProc:

  1. Write a static WndProc method that handles WM_GETMINMAXINFO, then forwards any other window messages to the original WndProc, via DefSubclassProc (or CallWindowProc in the examples), although note the disadvantages).
  2. Register your new WndProc via SetWindowSubclass (or SetWindowLongPtr in the examples).

This comes from an issue on the XAML GitHub repo.

See this similar question and this other similar question for more info.

Upvotes: 2

Related Questions