| MAUI-ContentPage | MAUI-TabbedPage | |
NavigationPage in .NET MAUI |
In .NET MAUI, a NavigationPage is a special type of page that provides a stack-based navigation model — meaning you can push new pages onto the stack and pop them off, much like moving forward and backward through screens.
App.xaml.cs
csharp
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
MainPage.xaml (ContentPage)
xml
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.MainPage"
Title="Home">
<StackLayout Padding="20">
<Label Text="Welcome to MAUI Navigation!"
FontSize="24" />
<Button Text="Go to Details"
Clicked="OnDetailsClicked" />
</StackLayout>
</ContentPage>
MainPage.xaml.cs
csharp
private async void OnDetailsClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new DetailsPage());
}
DetailsPage.xaml
xml
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.DetailsPage"
Title="Details">
<StackLayout Padding="20">
<Label Text="This is the details page." />
</StackLayout>
</ContentPage>
NavigationPage wraps MainPage.
Clicking the button pushes DetailsPage onto the stack.
The navigation bar automatically shows a back button to return.
| MAUI-ContentPage | MAUI-TabbedPage | |