Setting up navigation in a .NET MAUI Shell app
Effective navigation within the MVVM pattern begins with an integral component: a NavigationService
. This service is the driving force behind MVVM navigation. In essence, a NavigationService
is a class that implements an INavigationService
interface. The INavigationService
interface provides the contract for navigating between pages, defining the various methods needed for such operations. These methods could include operations such as GoToDetailPage()
, GoBack()
, and others, depending on your specific requirements.
Here’s the beauty of this setup: during the app’s startup, we register a framework-specific implementation of the INavigationService
interface with the DI container. It’s a perfect illustration of the power of DI, where we program to an interface, not an implementation. This allows our ViewModels to be completely platform-agnostic. This not only promotes code flexibility and testability but also allows...