Xamarin in Action
Creating native cross-platform mobile apps
Jim Bennett
  • MEAP began September 2016
  • Publication in Fall 2017 (estimated)
  • ISBN 9781617294389
  • 450 pages (estimated)
  • printed in black & white

Xamarin is a toolset that allows you to write native mobile apps in C# and run them on both iOS and Android devices. What makes Xamarin stand out from other cross-platform tools is that it gives you the ability to share large portions of code across these two platforms while still letting you write native apps that can take full advantage of the device and OS features specific to each platform. And since Xamarin was recently acquired by Microsoft, you can be sure the ecosystem will continue to grow - Xamarin has become a hugely important part of Microsoft's "any developer, any platform" mantra.

Xamarin in Action teaches you how to build Xamarin apps on iOS and Android from scratch while maximizing code re-use. This layer-by-layer guide starts by showing you the MVVM design pattern and explaining how it increases code sharing. Next, you'll start building an app from the ground up. You'll learn all the different layers inside a well written Xamarin app and discover how most of your code can be shared between iOS and Android. You'll look at how this code sharing can be best designed to allow unit testing of your business layer as well as your UI logic. Then you'll dig in to code that can?t be shared, like user interface code that's device specific. Finally, you'll learn how to take your app from final code to a tested and deployed version on the relevant store. By the end, you'll be able to build a high quality production-ready Xamarin app on iOS and Android from scratch with a high level of code reuse.

Table of Contents detailed table of contents

Part 1: Getting started with native cross-platform apps

1. Introducing native cross-platform applications with Xamarin

1.1. Introduction to Xamarin mobile apps

1.1.1. Vendor-specific native apps

1.1.2. Cordova

1.1.3. Xamarin native apps

1.1.4. Xamarin.Forms

1.1.5. Xamarin Developer tools

1.2. Mobile-optimized developer lifecycle

1.3. Introduction to production quality apps

1.3.1. Design

1.3.2. Source code control

1.3.3. Develop

1.3.4. Test

1.3.5. Build

1.3.6. Distribute

1.3.7. Monitor

1.4. Rinse and repeat���

1.5. Summary

2. Hello MVVM

2.1. What are UI design patterns?

2.1.1. Model-View-Controller

2.1.2. Model-View-Presenter

2.2. MVVM - the design pattern for Xamarin apps

2.3. What is Cross-platform code?

2.3.1. Portable Class libraries

2.3.2. Using PCLs to access device specific code

2.4. Getting started - creating your first solution

2.4.1. Requirements - what hardware or software do you need for each mobile platform?

2.4.2. Creating the solution

2.4.3. So what have we just created?

2.4.4. Building and running the apps

2.5. Is this really a cross-platform app?

2.6. Summary

3. MVVM — a deeper dive

3.1. The Model layer

3.1.1. The code should be cross-platform

3.1.2. The code should be testable

3.1.3. The model should represent data and business logic at the domain level not the UI level

3.2. The View Model layer

3.2.1. State and behavior

3.2.2. Value conversion

3.2.3. Testability

3.3. The View layer

3.4. Binding

3.4.1. Source and target

3.4.2. Binding mode

3.4.3. Binding is not cross-platform

3.4.4. Value converters

3.5. The Application layer

3.6. Navigation

3.6.1. View first

3.6.2. View model first

3.6.3. Which one to use?

3.7. Let's revisit our square root calculator app as a whole

3.8. Summary

4. Hello MVVM — a deeper dive

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

4.1.1. The model

4.1.2. The view model

4.1.3. The application layer

4.1.4. The view

4.2. Expanding on our Hello World app

4.2.1. Installing the Xamarin Text To Speech plugin

4.2.2. Adding the cross—platform code

4.2.3. Inversion of control

4.2.4. Wiring up the Android UI

4.2.5. Wiring up the iOS UI

4.2.6. Let's review the changes

4.3. Summary

5. What are we (a)waiting for? An introduction to multi-threading for Xamarin apps

5.1. Why do we need multi-threaded code?

5.2. What are threads?

5.2.1. Buying coffee

5.2.2. So what is a thread?

5.2.3. Quick round-up

5.3. UI thread and background threads

5.3.1. The UI thread

5.3.2. Background threads

5.4. Using tasks to run code in the background

5.4.1. Task and Task<T>

5.4.2. Chaining tasks

5.5. Task results

5.5.1. Polling to see if the task has finished

5.5.2. Waiting on the task

5.5.3. Getting the result from a continuation

5.5.4. Task exceptions

5.6. Updating the UI

5.6.1. The UI task scheduler

5.6.2. Using the power of MVVM

5.7. Async and await

5.7.1. The async and await keywords

5.7.2. Writing your own async methods

5.7.3. Async commands

5.8. Make your app feel responsive

5.9. The foundations have been laid, now its time to start building things

5.10. Summary

Part 2: From blank solution to an empty, working app

6. Designing MVVM cross-platform apps

6.1. Introduction to designing our cross-platform app

6.2. Designing the UI and user flows

6.2.1. SquareRt - a simple app for calculating square roots

6.2.2. Countr - an app for counting multiple things

6.2.3. Defining user flows and UIs

6.3. Architecting our app

6.3.1. Which layer?

6.3.2. Which thread?

6.3.3. Mapping your code to layers and threads

6.4. Creating the solutions

6.5. Application properties

6.5.1. Android manifest

6.5.2. iOS info.plist

6.6. SDK versions

6.6.1. Android SDK versions and the SDK manager

6.6.2. iOS SDK versions

6.7. Linking

6.7.1. Linking our apps

6.7.2. Linker options

6.7.3. Stopping the linker doing too much

6.8. Summary

7. Building cross-platform models

7.1. Building simple model layers

7.2. Unit testing

7.2.1. Creating a unit test project

7.2.2. Creating our first test

7.2.3. What do these tests tell us?

7.3. Building more complex model layers

7.3.1. Services, data models and repositories

7.3.2. Accessing databases

7.3.3. Adding a service layer

7.3.4. Accessing web services

7.4. A recap

7.5. Summary

8. Building cross-platform view models

9. Platform specific code - Android

10. Platform specific code - iOS

11. Running the app

Part 3: From a working app to a production ready app

12. Testing the app using UITest

13. Instrumentation and monitoring

14. Deploying the app


Appendix A: What are design patterns anyway?

Appendix B: Using someone else's code

Appendix C: UI flows and threads for SquareRt and Countr

What's inside

  • Understand MVVM and how it maximizes code reuse and testability
  • Build a mobile app from rough design through final deployable product
  • Creating cross platform model and UI logic layers
  • Build device specific UI?s for iOS and Android
  • Test apps through unit and automated UI testing
  • Prepare apps for publication with user tracking and crash analytics

About the reader

This book is for C# developers with a few months through many years of experience who want to build native mobile apps for iOS and Android using the language and toolset they already know.

About the author

Jim Bennett is a Xamarin MVP, Microsoft MVP, Xamarin Certified Developer and an active community member.. He's also a frequent speaker at events all around the world, including Xamarin user groups and Xamarin and Microsoft conferences. He regularly blogs about Xamarin development at https://jimbobbennett.io.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $49.99 pBook + eBook
MEAP eBook $39.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks