Book Image

Mastering Xamarin.Forms

By : Ed Snider
Book Image

Mastering Xamarin.Forms

By: Ed Snider

Overview of this book

Discover how to extend and build upon the components of the Xamarin.Forms toolkit to develop an effective, robust mobile app architecture. Starting with an app built with the basics of the Xamarin.Forms toolkit, we’ll go step by step through several advanced topics to create a solution architecture rich with the benefits of good design patterns and best practices. We’ll start by introducing a core separation between the app’s user interface and the app’s business logic by applying the MVVM pattern and data binding. Discover how to extend and build upon the components of the Xamarin.Forms toolkit to develop an effective, robust mobile app architecture. Starting with an app built with the basics of the Xamarin.Forms toolkit, we’ll go step by step through several advanced topics to create a solution architecture rich with the benefits of good design patterns and best practices. We’ll start by introducing a core separation between the app’s user interface and the app’s business logic by applying the MVVM pattern and data binding. Then we will focus on building out a layer of plugin-like services that handle platform-specific utilities such as navigation, geo-location, and the camera, as well as how to use these services with inversion of control and dependency injection. Next we’ll connect the app to a live web-based API and set up offline synchronization. Then, we’ll dive into testing the app—both the app logic through unit tests and the user interface using Xamarin’s UITest framework. Finally, we’ll integrate Xamarin Insights for monitoring usage and bugs to gain a proactive edge on app quality.
Table of Contents (17 chapters)

Adding MVVM to the app


The first step of introducing MVVM into an app is to set up the structure by adding folders that will represent the core tenants of the pattern—Models, ViewModels, and Views. Traditionally, the Models and ViewModels live in a core library (usually a portable class library), while the Views live in a platform-specific library. However, thanks to the power of the Xamarin.Forms toolkit and its abstraction of platform-specific UI APIs, the Views in a Xamarin.Forms app can also live in the core library.

Tip

Just because the Views can live in the core library with the ViewModels and Models doesn't mean that separation between the user interface and the app logic isn't important.

In some mobile app architectures, the Models portion of the app might live all alone in its own library so that the models can be shared by other applications or also be used for other purposes.

When implementing a specific structure to support a design pattern, it is helpful to have your application...