0

How can I define the dimensions (width and height) so that when starting / debugging a .NET MAUI application with the Windows Machine target the window that opens will have those dimensions? When changing the window size manually the resulting width and height won't be saved so I have to repeat this every time.

I assume it can somehow be done in "launchSettings.json" -> "profiles" -> "Windows Machine"? If not how else can I change the launch settings?

ToolmakerSteve
  • 18,547
  • 14
  • 94
  • 196
user764754
  • 3,865
  • 2
  • 39
  • 55
  • Does this answer your question? [MAUI .NET Set Window Size](https://stackoverflow.com/questions/72399551/maui-net-set-window-size) – ToolmakerSteve Mar 29 '23 at 00:56

1 Answers1

1

You can rewrite the CreateWindow method in the App class to create a new window, set the maximum and minimum width and height. I wrote a demo and did a simple test, refer to the following code:

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        //MainPage = new AppShell();
    }

    protected override Window CreateWindow(IActivationState activationState)
    {
        var window = new Window();
        window.MaximumHeight = 500;
        window.MaximumWidth = 500;
        window.MinimumHeight = 500;
        window.MinimumWidth = 500;
        window.Page =new AppShell();
        return window;
    }
}

Hope it helps you.

Zack
  • 1,255
  • 1
  • 2
  • 5