Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting of MainPage equivalent after deprecation

Tags:

maui

I have a Xamarin Forms app that I am updating to use Maui 9. In my app, there are a couple of places where I need to change the top-level page. I was able to do this by setting the MainPage property of the app.

The release notes for Maui 9 say to override CreateWindow to set MainPage at the start of the app, and use Application.Current.Windows[0].Page to get the page, but I can see no other way of setting MainPage... can anyone suggest how I can achieve the equivalent of setting MainPage (other than overriding CreateWindow)?

like image 541
Sparky Avatar asked Aug 31 '25 03:08

Sparky


1 Answers

Code that accesses the Application.Current.MainPage property should now access the Application.Current.Windows[0].Page property for apps with a single window.

As mentioned in documentation here. If you want to set Mainpage in runtime.You can define something like this.

   Application.Current.Windows[0].Page = new NewMainPage();
like image 170
Bhavanesh N Avatar answered Sep 02 '25 22:09

Bhavanesh N