How to change the size between Pages in Windows Desktop app

Bui Minh Tam 0 Reputation points
2023-09-16T05:07:15.1366667+00:00

I am using below environment to create windows desktop app + Maui / Net 7 + Windows 10

I need to set the size for each screen, for example: + LoginPage : width (400), height(650) + MenuPage : width (600), height(800)

I have referred to the link creation settings below: https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/windows

However, for "LoginPage" it is OK but "MenuPage" gives an error: "Object reference not set to an instance of an object."

Below is my "MenuPage" source and the error that occurs at the line "this.Window.Width = width;"

public partial class Index : ContentPage
{
   publicIndex()
   {
     InitializeComponent();
   }

   protected override void OnAppearing()
   {
         try
         {
             base.OnAppearing();

             const int width = 800;
             const int height = 600;

             this.Window.Width = width;
             this.Window.Height = height;
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.ToString());
         }
   }
}

I want to ask is there any way to set the size for each page?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,391 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bui Minh Tam 0 Reputation points
    2023-09-16T07:42:38.7166667+00:00

    I fixed it by replacing "this.Windows" with "Shell.Current.Window"

    The cause is unknown but may be due to application problems:

    await Shell.Current.GoToAsync...


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.