How do you set the startup page size in dotnet MAUI for WinUI platform?

dg2k 1,386 Reputation points
2022-05-15T22:22:59.103+00:00

On a start up, I want to set the page size of my MAUI app for Windows platform (say, 500×1080). What is the recommended place to set the page size and how to do it?

I tried the same for XF and none of the suggestions in MainPage.xaml.cs of UWP project worked for me.

I am hoping that .Net MAUI has a straightforward solution for the simple task of setting a page size as required when an app starts for page-resizable platforms like WinUI.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,900 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rob Caplan - MSFT 5,412 Reputation points Microsoft Employee
    2022-05-16T01:23:10.097+00:00

    MAUI for Windows runs on WinUI not UWP, so UWP methods aren't applicable. WinUI gives greater access to native window and window management API.

    The WinUI way to set the page size is to manage the WinUI AppWindow. From a MAUI app you can do this when the window is created by managing the OnWindowCreated lifecycle event.

    There is a discussion of this with unofficial sample code in the MAUI repo at: https://github.com/dotnet/maui/discussions/2370 . Even though the poster's original goal was for MAUI Blazor+WinUI, there is nothing Blazor related in the answer. This all happens in the MAUI + WinUI frame outside of the Blazor control.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. 2022-12-15T14:48:46.31+00:00

    Maybe you want to check this link, about .NET MAUI for .NET 7 news....

    https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/windows?view=net-maui-7.0

    0 comments No comments