Implementing MVVM in WinUI applications
It’s time to start converting our project to use MVVM. To gain a thorough understanding of the MVVM pattern, we will start by building our own MVVM infrastructure. For simple applications, it doesn’t require more than a single base class:
- Start by adding a ViewModels folder to the project. If you are using the code from GitHub, you can either continue with your project from the previous chapter or use the Start project in the folder for this chapter.
- Next, add a new class to the ViewModels folder and name it
BindableBase
. This will be the base class for all our View Model classes in the project. It will be responsible for notifying the corresponding views of any property changes. This is accomplished by implementing theINotifyPropertyChanged
interface. Let’s review theBindableBase
class code, as follows:public class BindableBase : INotifyPropertyChanged { public event PropertyChangedEventHandler...