Using MVVM – creating views and ViewModels
Model-View-ViewModel, or MVVM for short, is all about separation of concerns. It is an architectural pattern that defines three parts, each of which has a specific meaning:
- Model: This relates to anything that represents data and that can be referenced with
ViewModel
. - View: This is the visual component. In .NET MAUI, this is represented by a page.
- ViewModel: This is the class that acts as the glue between the model and the view.
We are introducing MVVM here because the MVVM pattern was designed specifically around XAML-based GUIs. This app and the rest of the apps in this book will use XAML to define the GUI and we will use the MVVM pattern to separate the code into the three aforementioned parts.
In this app, we could say that the model is the repository and the to-do list items it returns. ViewModel
refers to this repository and exposes properties that the view can bind to. The ground rule is that any logic...