Chapter 8. Building cross-platform view models

 

This chapter covers

  • Creating simple and master/detail view models
  • Adding state to view models using single-value and collection properties
  • Adding behavior to view models when properties change and using commands
  • Communicating between components using messaging
  • View-model navigation

In the previous chapter we built the cross-platform model layers for our two apps, SquareRt and Countr. We looked at how you can wrap up your model layer in services and repositories that can be shared among different view models. Now it’s time to move up a layer and start coding the view models.

8.1. The view-model layer

Like the model layer, the view-model layer is a cross-platform layer (figure 8.1). The difference is that whereas the model layer represents your data and business logic in a way that makes sense to your domain (for example, using services), the view-model layer represents the state and behavior of your UI and is written in a way that makes sense to your view layer.

Figure 8.1. The view-model layer in an MVVM-based mobile app is written using cross-platform code.

8.2. Adding state and behavior to SquareRt

8.3. Adding state and behavior to Countr

8.4. A quick roundup

Summary