In MAUI apps, how can I completely disable window resize and fix the width and height to something like 200px?
Visual Studio automatically generates this code:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
}
The Height
and Width
properties are readonly. I have found a RequestedWidth
but it doesn’t change anything. When I try to change the base class to something else, I get an error saying that is not authorized.
I don’t really care if fixing the size does not make sense in Android or similar operating systems, it is important in Windows. So is there any way to do this?
2
Answers
For windows, after the font settings, you can add this code to your
MauiProgram.cs
file. This will disable resize. Optionally you can change border and title bar visibility too. If you don’t disable title bar and border, buttons in the upper right corner of the window will be still visible and users still be able to switch your app to full screen mode. I recommend you to disable them too. Finally if you want to disable title bar you should setExtendsContentIntoTitleBar
property tofalse
too. If you don’t, you’ll still see half the title bar.Now your Window size is fixed but it’s height & width still at default value. You should add this code to your
MainPage.xaml.cs
;You can rewrite the
CreateWindow
method in the App class to create a new window, set the maximum and minimum width and height, refer to the following code: