| MAUI-Pages | MAUI-Navigationpage | |
ContentPage in .NET MAUI |
In .NET MAUI, a ContentPage is the most commonly used page type β essentially a single screen that hosts your UI. Itβs the foundation for most app views and is designed to hold one main layout, which in turn contains child controls.
xml
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.MainPage">
<StackLayout Padding="20">
<Label Text="Welcome to MAUI!"
FontSize="24"
HorizontalOptions="Center" />
<Entry Placeholder="Enter your name"
Text="{Binding UserName}" />
<Button Text="Submit"
Command="{Binding SubmitCommand}" />
</StackLayout>
</ContentPage>
The Shell is a high-level container that organizes your appβs navigation. It can host ContentPages directly, or group them into tabs and flyouts. This makes navigation simpler and more declarative compared to manually managing NavigationPage stacks.
AppShell.xaml
xml
<Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MyApp"
x:Class="MyApp.AppShell">
<!-- Flyout Item -->
<FlyoutItem Title="Home" Icon="home.png">
<ShellContent ContentTemplate="{DataTemplate local:MainPage}" />
</FlyoutItem>
<!-- Tabbed Navigation -->
<TabBar>
<ShellContent Title="Dashboard" ContentTemplate="{DataTemplate local:DashboardPage}" />
<ShellContent Title="Settings" ContentTemplate="{DataTemplate local:SettingsPage}" />
</TabBar>
</Shell>
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">
<StackLayout Padding="20">
<Label Text="Welcome to MAUI Shell!"
FontSize="24"
HorizontalOptions="Center" />
<Button Text="Go to Details"
Command="{Binding NavigateToDetailsCommand}" />
</StackLayout>
</ContentPage>
csharp
await Shell.Current.GoToAsync("//DashboardPage");
| MAUI-Pages | MAUI-Navigationpage | |