9 The MVVM Pattern

 

This chapter covers

  • The Model, View, ViewModel (MVVM) paradigm
  • The problems that MVVM solves in complex apps
  • Making controls MVVM friendly with behaviors

The Model, View, ViewModel (MVVM) pattern was introduced by Microsoft with Windows Presentation Foundation and has become the standard for apps developed using XAML. It’s a popular pattern with enough nuance that entire books have been dedicated to the subject. This chapter will provide an introduction, and as you progress through your .NET MAUI journey, you may find that you want to explore this topic in more depth.

The use of the MVVM pattern is, in some ways, more of an art than a science. You should aim to understand the rules about separating UI logic, presentational logic, and business logic if you are adopting the MVVM pattern in your app. Of course, blind adherence to any pattern is an antipattern, and you should prioritize ensuring that your code is readable and maintainable. But you can’t make an informed decision about when to deviate from the pattern if you don’t understand it well.

9.1 Refactoring the MauiTodo app for MVVM

 

9.2 Using behaviors to augment your controls

 

9.3 What is MVVM?

 
 

9.3.1 The Model

 
 
 

9.3.2 The View

 
 

9.3.3 The ViewModel

 
 
 

9.3.4 Binding from Views to ViewModels

 

9.3.5 Putting it all together

 
 
 
 

9.4 The MauiStockTake app without MVVM

 
 
 

9.5 The MauiStockTake app in MVVM

 
 

9.5.1 The Model

 
 
 

9.5.2 The ViewModel

 

9.5.3 The View

 
 

9.5.4 Adding the Search functionality

 
 
 

9.5.5 Adding the inventory functionality

 
 

9.6 Reviewing the MauiStockTake app so far

 

Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest