Mastering Xamarin.Forms

Book description

Build rich, maintainable multiplatform native mobile apps with Xamarin.Forms

About This Book

  • Build an effective mobile app architecture with the Xamarin.Forms toolkit
  • Maximize the testability, flexibility, and overall quality of your Xamarin.Forms mobile app
  • This step-by-step tutorial is packed with real-world scenarios and solutions to build professional grade mobile apps with Xamarin.Forms

Who This Book Is For

This book is intended for C# developers who are familiar with the Xamarin platform and the Xamarin.Forms toolkit. If you have already started working with Xamarin.Forms and want to take your app to the next level and make it more maintainable, testable, and flexible, then this book is for you.

What You Will Learn

  • Find out how, when, and why you should use architecture patterns and get best practices with Xamarin.Forms
  • Implement the Model-View-ViewModel (MVVM) pattern and data-binding in Xamarin.Forms mobile apps
  • Extend the Xamarin.Forms navigation API with a custom ViewModel-centric navigation service
  • Leverage the inversion of control and dependency injection patterns in Xamarin.Forms mobile apps
  • Work with online and offline data in Xamarin.Forms mobile apps
  • Test both business logic and user interface code in Xamarin.Forms mobile apps
  • Use platform-specific APIs to build rich custom user interfaces in Xamarin.Forms mobile apps
  • Explore how to improve mobile app quality with analytics and crash reporting using Xamarin Insights

In Detail

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.

Style and approach

This easy-to-follow, code-rich guide will walk you through building a real-world Xamarin.Forms mobile app from start to finish. Each chapter builds upon the app by applying new advanced functionalities, design patterns, and best practices.

Table of contents

  1. Mastering Xamarin.Forms
    1. Table of Contents
    2. Mastering Xamarin.Forms
    3. Credits
    4. About the Author
    5. Acknowledgments
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
        6. Sources
    9. 1. Getting Started
      1. Introducing the app idea
        1. Defining features
      2. Creating the initial app
        1. Setting up the solution
          1. Updating the Xamarin.Forms packages
        2. Creating the main page
          1. Running the app
        3. Creating the new entry page
        4. Creating the entry detail page
      3. Summary
    10. 2. MVVM and Data Binding
      1. Understanding the MVVM pattern
      2. Adding MVVM to the app
        1. Setting up the app structure
        2. Adding ViewModels
          1. Adding MainViewModel
          2. Adding DetailViewModel
          3. Adding NewEntryViewModel
      3. Summary
    11. 3. Navigation Service
      1. The Xamarin.Forms navigation API
      2. Navigation and MVVM
        1. ViewModel-centric navigation
      3. Creating a navigation service
        1. Updating the TripLog app
          1. Updating BaseViewModel
          2. Updating MainViewModel
            1. Initializing MainViewModel
          3. Updating NewEntryViewModel
          4. Updating DetailPage
      4. Summary
    12. 4. Platform Specific Services and Dependency Injection
      1. Inversion of control and dependency injection in mobile apps
      2. The Xamarin.Forms DependencyService versus third-party alternatives
      3. Creating and using platform-specific services
        1. Creating a location service
        2. Using the location service on the new entry page
          1. Adding the location service implementation
      4. Registering dependencies
        1. Registering the platform-service implementations
        2. Registering the ViewModels
        3. Registering the navigation service
        4. Updating the TripLog app
        5. Updating the navigation service to handle ViewModel creation and dependency injection
      5. Summary
    13. 5. User Interface
      1. Custom Renderers
        1. Creating a TableView DatePicker
      2. Value Converters
        1. Creating a reverse visibility Value Converter
        2. Creating an integer to image Value Converter
      3. Summary
    14. 6. API Data Access
      1. Creating an API with Microsoft Azure App Services
        1. Browsing and adding data
      2. Creating a base HTTP service
      3. Creating an API Data Service
        1. Updating the TripLog app ViewModels
      4. Offline data caching
        1. Adding the Akavache library
        2. Maintaining an offline data cache
      5. Summary
    15. 7. Authentication
      1. Adding identity and authentication to Azure Mobile Apps
        1. Setting up permissions
        2. Setting up an identity provider
      2. Creating an authentication service
      3. Adding a sign in page
      4. Summary
    16. 8. Testing
      1. Unit testing
        1. Testing ViewModels
        2. Running unit tests in Xamarin Studio
      2. Automated UI testing
        1. The Xamarin UITest framework
          1. Common UITest methods
        2. Creating a UITest project in Xamarin Studio
        3. Initializing the TripLog app for UITest
        4. Testing views
        5. Running UI tests
          1. Running UI tests locally
            1. Enabling screenshots
          2. Running UI tests in Xamarin Test Cloud
      3. Summary
    17. 9. App Analytics
      1. Mobile app analytics and crash reporting
      2. Xamarin Insights
        1. Setting up Xamarin Insights
        2. Creating an analytics service
        3. Tracking exceptions and events
      3. Summary
    18. Index

Product information

  • Title: Mastering Xamarin.Forms
  • Author(s): Ed Snider
  • Release date: January 2016
  • Publisher(s): Packt Publishing
  • ISBN: 9781785287190