.NET MAUI – Adding a new page and redirect

January 15, 2022

This tutorial demonstrates how to create a new MAUI page and redirect upon clicking a button.

Microsoft Visual Studio Community 2022 (64-bit) - Preview
Version 17.1.0 Preview 2.0
Microsoft .NET Framework Version 4.8.09014

1. Right click the project .csproj.

2. Click New Item under Add.

3. Select .NET MAUI ContentPage (C#)(Preview).

Add .NET MAUI ContentPage

4. On MainPage.xaml, add a button with button click listener.

<Button 
 Text="Redirect To Settings Page"
 FontAttributes="Bold"
 Grid.Row="3"
 Clicked="OnSettingsButtonClicked"
 HorizontalOptions="Center" />

5. On MainPage.xaml.cs, add the button click listener method.

private void OnSettingsButtonClicked(object sender, EventArgs e)
{
	Application.Current.MainPage.Navigation.PushModalAsync(new SettingsPage(), true);
}

6. On added page (Mine is SettingsPage.xaml), add page UI.

7. We need to register the newly created page. This is done in App.xaml.cs file. Add following line to bottom of App() constructor.

Routing.RegisterRoute(nameof(SettingsPage), typeof(SettingsPage));

Done!! Now run the application and check if you can navigate to another page.