Page navigation with MVVM and DI
Until this point, the application has consisted of only a single window. Now it’s time to implement page navigation by adding a host Frame
and two Page
objects so we can handle adding new items or editing existing items. The new Page
will be accessible from the Add/Edit Item button or by double-clicking on an item in the list.
Migrating MainWindow to MainPage
If you’re familiar with UWP app development, you should already understand page navigation. In UWP, the application consists of only a single window. At the root of the window, there is a Frame
object, which hosts pages and handles the navigation between them. To achieve the same result in a desktop WinUI 3 app, we will create a new MainPage
, move all the XAML content from MainWindow
into MainPage
, and update the App
class to create a Frame
as the new content of MainWindow
. Then we can display the same contents by navigating to MainPage
. Let’s get started:
- First...