.netmauimaui-windows

Minimum window size in .NET MAUI


Quick question that I cannot find any good answers to: I want my program window to be possible to resize on desktop. But there should be a minimum possible size to the window. How do I set this in .NET MAUI?

For example, with Avalonia, I do this by setting MinHeight="400" and MinWidth="800" in the XAML properties for <Window>.


Solution

  • You can override the CreateWindow method in the App.xaml.cs.

     protected override Window CreateWindow(IActivationState activationState)
     {
              var window = base.CreateWindow(activationState);
              window.MinimumHeight = 600; // set minimal window height
              window.MinimumWidth = 800; // set minimal window width
              return window;
     }