Chapter 4. Hello again, MVVM—understanding and enhancing our simple MVVM app

 

This chapter covers

  • A detailed look into the code of the Hello Cross-Platform World app from chapter 2
  • MvvmCross classes that provide a base implementation of a view model, a command, and some cross-platform app logic
  • How to use MvvmCross to bind iOS and Android views to the view model
  • Using Xamarin plugins to add cross-platform wrappers around platform-specific functionality
  • Using inversion of control to loosely couple your code for unit testing
  • Creating and binding a command
  • Adding code to the view model to make your app speak to you

4.1. A deeper dive into our Hello Cross-Platform World app

Now that we’ve covered MVVM in detail, it’s a good opportunity to review the Hello Cross-Platform World app you built in chapter 2 to see what the code does, and how it fits into the layers for a Xamarin app. You built the app using the MvvmCross extension, which created a simple Hello World app in which editing the value in a text box updated a label to match. It was a cross-platform app, and we proved this by changing a string in the core project and seeing that both apps were updated.

Let’s start working through the model layers from the bottom up.

4.1.1. The model

Starting from the bottom up, let’s think about the model. This is a simple app with a single string value, so there really isn’t a model layer as such. You can think of the hello string field as the model.

4.2. Expanding on our Hello World app

Summary