.NET MAUI Navigation Tutorials
Master the art of navigating between pages and views in your .NET MAUI applications. This section covers various navigation patterns, from simple page-to-page transitions to complex hierarchical navigation and shell navigation.
-
Basic Page Navigation
Learn how to navigate between pages using the navigation stack. Understand PushAsync, PopAsync, and their variations.
-
Passing Data Between Pages
Discover effective ways to pass data from one page to another during navigation, ensuring your application state is maintained.
-
Navigation with .NET MAUI Shell
Explore the powerful navigation capabilities of .NET MAUI Shell, including tab bars, flyouts, and routing.
-
Modal Page Navigation
Implement modal pages for focused user interactions and workflows, such as displaying forms or dialogs.
-
Handling Navigation Parameters
Learn how to define and use navigation parameters to dynamically load content and configure target pages.
-
Custom Navigation Transitions
Enhance user experience with custom animations and transitions between pages.
Key Concepts
Understanding these core concepts will help you build robust navigation experiences:
Navigation Stack
The navigation stack is a Last-In, First-Out (LIFO) collection of pages that the application is currently navigating through. When you navigate to a new page using Navigation.PushAsync(newPage)
, the new page is added to the top of the stack. When you navigate back using Navigation.PopAsync()
, the top page is removed from the stack, and the previous page becomes visible.
Navigation Service
For more complex applications, implementing a dedicated navigation service can abstract navigation logic, making your code cleaner and more maintainable. This service often uses dependency injection to provide navigation capabilities throughout your app.
.NET MAUI Shell
Shell simplifies the development of cross-platform applications by providing a standard navigation experience. It enables features like tabbed interfaces, flyout menus, and URI-based routing out-of-the-box, reducing boilerplate code.
Getting Started with Navigation
To begin navigating, you typically need to obtain an instance of the INavigation
interface. In most scenarios within a page, you can access it via the Navigation
property of the ContentPage
:
// Example in a ContentPage code-behind
async void OnNavigateToNextPageClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new NextPage());
}
For scenarios outside of a page, such as in ViewModels, you'll often inject a navigation service that provides access to the INavigation
interface or implements its own navigation patterns.