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
- 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
MainViewModelclass. The first thing we need to do to use the MVVM Toolkit’s source generators is update
MainViewModelto be a partial class and have it inherit from
CommunityToolkit.Mvvm.ComponentModel.ObservableObjectinstead of our own
public partial class MainViewModel : ObservableObject
To learn more about how the MVVM Toolkit uses...