-
Normal Page Mode
In the constructor ofApp.xaml.cs
, replace theMainPage
object.1 2 3 4 5 6
public App() { InitializeComponent(); MainPage = new NewPage1(); }
-
MVVM Mode
Override theCreateWindow
method inApp.xaml.cs
.1 2 3 4 5 6 7 8 9 10
protected override Window CreateWindow(IActivationState? activationState) { NewPage1? desktopShellService = Handler.MauiContext!.Services.GetService<NewPage1>(); Window window = new Window(desktopShellService) { Width = DeviceDisplay.Current.MainDisplayInfo.Width / 2, Height = DeviceDisplay.Current.MainDisplayInfo.Height / 2, }; return window; }
-
Switch from Splash Screen to Main Page
In the page’s Loaded event or other events, add code to switch theMainPage
object.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
async Task Loaded() { await Task.Delay(5000); _ = Task.Run(() => { AppShell? desktopShellService = Application.Current.Handler.MauiContext!.Services.GetService<AppShell>(); if (desktopShellService != null && desktopShellService != Application.Current.MainPage) { MainThread.BeginInvokeOnMainThread(() => { Application.Current.MainPage = desktopShellService; }); } }); //AppShell? desktopShellService = Application.Current.Handler.MauiContext!.Services.GetService<AppShell>(); //if (desktopShellService != null && desktopShellService != Application.Current.MainPage) //{ // Application.Current.MainPage = desktopShellService; //} }