Decoupling the UI from the view model
The .NET MAUI platform includes core features to separate the view and view model:
- Bindings transfer data between the view and view model
- The
BindingContext
property allows you to specify to what view model your view should be bound - Commands help you pass actions (such as button clicks) from the view to the view model
Let’s transform the default .NET MAUI project created by Visual Studio into an MVVM project.
Getting ready
To prepare for the first step of this recipe, create a basic .NET MAUI application from the default project template available in Visual Studio. If you are using another IDE (VS Code, Rider) and with non-default project templates, you can download a starting application from this GitHub repository: https://github.com/PacktPublishing/.NET-MAUI-Cookbook/tree/main/Chapter02/c2-DecoupleViewAndViewModel. This repository also contains code with the complete steps of this recipe.