Page navigation with MVVM and DI
Until this point, the application has consisted of only a single page. It is now time to add a second page to handle adding new items or editing existing items. The page will be accessible from the Add/Edit button or by double-clicking on an item in the list.
Adding ItemDetailsPage
The full ItemDetailsPage.xaml
code can be found on GitHub (https://github.com/PacktPublishing/-Learn-WinUI-3.0/blob/master/Chapter04/Complete/MyMediaCollection/Views/ItemDetailsPage.xaml). You can follow along with the steps in this section or review the final code on GitHub.
Note
The project will not compile successfully until we have added the new view model to the project and added it to the DI container for consumption by the view. Before we add the view model, we need to create a couple of services to enable page navigation and data persistence between pages.
To add ItemDetailsPage
, let's follow these steps:
- Add a new folder to the project...