Implementing MVVM in WinUI applications
It's time to start converting our project to use MVVM. As we previously learned, we can best leverage the power and performance of WinUI bindings if we build our own MVVM framework. For most applications, it's not much 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 itBindableBase
. This will be the base class for all of 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...