Leveraging the MVVM Toolkit
We briefly introduced the MVVM Toolkit earlier in the chapter. In this section, we will update the MainViewModel
to see how we can remove the need for a BindableBase
class and reduce the amount of code in the view model itself:
- Start by right-clicking on the solution file in Solution Explorer and select Manage NuGet Packages for Solution.
- In the NuGet window, select the Browse tab and search for
CommunityToolkit.Mvvm
. - Select the CommunityToolkit.Mvvm package in the results and install the latest stable version (8.2.0 or later).
- Close the NuGet window and open the
MainViewModel
class. The first thing we need to do to use the MVVM Toolkit’s source generators is updateMainViewModel
to be a partial class and have it inherit fromCommunityToolkit.Mvvm.ComponentModel.ObservableObject
instead of our ownBindableBase
class:public partial class MainViewModel : ObservableObject
Note
To learn more about how the MVVM Toolkit uses...