Search code examples
c#maui.net-9.0content-pages

How do I set the size of a content page of a maui app in a .NET 9.0 framework


I'm looking to set a specific size to my content page in my maui app. At first I had this problem resolved because I was using .NET 8.0 and the code in my App.xaml.cs file is:

protected override Window CreateWindow(IActivationState? activationState)
{
    var wins = base.CreateWindow(activationState);

    const int newheight = 715;
    const int newwidth = 1290;

    wins.Height = wins.MinimumHeight = wins.MaximumHeight = newheight;
    wins.Width = wins.MinimumWidth = wins.MaximumWidth = newwidth;

    return wins;
}

And that worked with no problem in a .NET 8.0 framework, but now I've upgraded to a .NET 9.0 and now it won.t even let me add the protected override Window CreateWindow() line in there.

So is there a different way to set the content page size in a .NET 9.0 framework maui app?


Solution

  • As mentioned in documentation here.

    From .NET 9 preferred way to set first page of app is to override CreateWindow and pass the first page to newly created Window object.

    Here, you can set window's height and width as well.

    protected override Window CreateWindow(IActivationState? activationState)
    {
       const int newheight = 715;
       const int newwidth = 1290;
    
       var wins = new Window(//object of your first page);
       wins.Height = wins.MinimumHeight = wins.MaximumHeight = newheight;
       wins.Width = wins.MinimumWidth = wins.MaximumWidth = newwidth;
       return wins;
    }
    

    Although in your previous case and this case you're not setting height & width of a "content page", your'e setting height & width of your app's window.