O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mastering Xamarin.Forms - Second Edition

Book Description

Create high-quality multi-platform native apps with Xamarin.Forms

About This Book

  • Packed with real-world scenarios and solutions to help you build professional-grade mobile apps with Xamarin.Forms
  • Build an effective mobile app architecture with the Xamarin.Forms toolkit
  • Find out how, when, and why you should use architectural patterns and get best practices 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 with higher quality, maintainability, testability, and flexibility, then this book is for you.

What You Will Learn

  • Implement the Model-View-View-Model (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 business logic 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 using Visual Studio AppCenter

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, you'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.

You'll start by introducing a core separation between the app's user interface and its business logic by applying the MVVM pattern and data-binding. Then you focus on building out a layer of plugin-like services that handle platform-specific utilities such as navigation and geo-location, and on how to loosely use these services in the app with inversion of control and dependency injection. Next you connect the app to a live web-based API and set up offline synchronization. Then, you delve into testing the app logic through unit tests. Finally, you set up Visual Studio App Center 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 on the app by applying new advanced capabilities, design patterns, and best practices. Packed with real-world scenarios, this step-by-step guide will help you quickly build professional-grade apps with Xamarin.Forms.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Table of Contents

  1. Title Page
  2. Copyright and Credits
    1. Mastering Xamarin.Forms Second Edition
  3. Dedication
  4. www.packtpub.com
    1. Why subscribe?
    2. PacktPub.com
  5. Foreword
  6. Contributors
    1. About the author
    2. Acknowledgments
    3. About the reviewer
    4. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
      1. Download the example code files
      2. Conventions used
    4. Get in touch
      1. Reviews
  8. 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
      3. Creating the new entry page
      4. Creating the entry detail page
    3. Summary
  9. 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
  10. Navigation
    1. The Xamarin.Forms navigation API
    2. Navigation and MVVM
      1. The 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
  11. Platform Specific Services and Dependency Injection
    1. Inversion of control and dependency injection in mobile apps
    2. 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
      3. 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
  12. 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. Adding pull-to-refresh
    4. Accessibility 
      1. Supporting screen readers
    5. Summary
  13. API Data Access
    1. Creating an API with Microsoft's Azure App Service
      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
  14. 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
  15. Testing
    1. Unit testing
      1. Testing ViewModels
      2. Running unit tests in Visual Studio
    2. Summary
  16. App Monitoring
    1. Mobile app analytics and crash reporting
    2. Visual Studio App Center
      1. Setting up Visual Studio App Center
      2. Creating an analytics service
      3. Tracking exceptions and events
    3. Summary
  17. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think