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
The recommended solution, implemented on GitHub, is to use P/Invoke to call the window subclassing functions SetWindowSubclass and DefSubclassProc:
WM_GETMINMAXINFO, then forwards any other window messages to the original WndProc, via DefSubclassProc (or CallWindowProc in the examples), although note the disadvantages).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.
If anyone is wanting a modern solution, please add the following to your MainWindow():
OverlappedPresenter presenter = OverlappedPresenter.Create();
presenter.PreferredMinimumWidth = 300;
presenter.PreferredMinimumHeight = 400;
this.AppWindow.SetPresenter(presenter);
This way you don't need to recreate the OverlappedPresenter:
public MainWindow()
{
InitializeComponent();
if (this.AppWindow.Presenter is OverlappedPresenter presenter)
{
presenter.PreferredMinimumWidth = 300;
presenter.PreferredMinimumHeight = 400;
}
}