Mastering Xamarin.Forms
eBook - ePub

Mastering Xamarin.Forms

App architecture techniques for building multi-platform, native mobile apps with Xamarin.Forms 4, 3rd Edition

  1. 200 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Mastering Xamarin.Forms

App architecture techniques for building multi-platform, native mobile apps with Xamarin.Forms 4, 3rd Edition

About this book

New edition of the bestselling guide to building an effective mobile app architecture with Xamarin.Forms 4 that maximizes the overall quality of apps.

Key Features

  • Updated for Xamarin.Forms 4
  • Packed with real-world scenarios and solutions to help you build professional grade mobile apps with Xamarin.Forms
  • Includes design patterns and best practice techniques that every mobile developer should know

Book Description

Discover how to extend and build upon the components of the most recent version of Xamarin.Forms to develop an effective, robust mobile app architecture. This new edition features Xamarin.Forms 4 updates, including CollectionView and RefreshView, new coverage of client-side validation, and updates on how to implement user authentication.

Mastering Xamarin.Forms, Third Edition is one of the few Xamarin books structured around the development of a simple app from start to finish, beginning with a basic Xamarin.Forms app and going step by step through several advanced topics to create a solution architecture rich with the benefits of good design patterns and best practices.

This book introduces a core separation between the app's user interface and the app's business logic by applying the MVVM pattern and data binding, and then focuses on building a layer of plugin-like services that handle platform-specific utilities such as navigation and geo-location, as well as how to loosely use these services in the app with inversion of control and dependency injection. You'll connect the app to a live web-based API and set up offline synchronization before testing the app logic through unit testing. Finally, you will learn how to add monitoring to your Xamarin.Forms projects to track crashes and analytics and gain a proactive edge on quality.

What you will learn

  • Find out how, when, and why to use architecture patterns and best practices with Xamarin.Forms
  • Implement the Model-View-ViewModel (MVVM) pattern and data binding in Xamarin.Forms mobile apps
  • Incorporate client-side validation 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
  • Use platform-specific APIs to build rich custom user interfaces in Xamarin.Forms mobile apps
  • Explore how to monitor mobile app quality using Visual Studio App Center

Who this book is for

This book is intended for.NET developers who are familiar with Xamarin mobile application development and the open source Xamarin.Forms toolkit. If you have already started working with Xamarin.Forms and want to take your app to the next level, making it more maintainable, testable and flexible, then this book is for you.

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, weโ€™ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere โ€” even offline. Perfect for commutes or when youโ€™re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Mastering Xamarin.Forms by Ed Snider in PDF and/or ePUB format, as well as other popular books in Computer Science & Application Development. We have over one million books available in our catalogue for you to explore.

3

Navigation

The overarching goal of this book is to show how you can build a solid architecture based on design patterns and best practices; the objective of this chapter is to take our TripLog app one step closer to achieving that goal. By introducing MVVM into our TripLog app in Chapter 2, MVVM and Data Binding, we set up the app with a very clear pattern to separate the user interface from the rest of the logic in the app. Each subsequent chapter, starting with this one, further advances this concept of separation.
In Chapter 2, MVVM and Data Binding, we moved a large portion of the app logic into ViewModels; however, navigation is still being initiated from the Pages (Views). In this chapter, we will create a navigation service that we can use to refactor any navigation logic out of the Page-level code and into the ViewModels. While doing this will not result in any noticeable differences when running the app, it will allow us to make navigation fit more naturally into the rest of the app's logic. Furthermore, as we will see in Chapter 8, Testing, having an abstracted navigation service means we can include assertions about navigation when testing the logic in our ViewModels.
Here's a quick look at what we'll cover in this chapter:
  • Understanding the basics of the Xamarin.Forms navigation API
  • Thinking about navigation in MVVM
  • Creating a navigation service
  • Updating the TripLog app to use the navigation service
We'll start by reviewing the navigation API that comes with Xamarin.Forms.

The Xamarin.Forms navigation API

Along with abstracting common user interface elements into a multi-platform API, Xamarin.Forms also abstracts navigation for iOS, Android, and Windows into a single easy-to-use navigation service. Each mobile platform does navigation in a slightly different way and has a slightly different navigation API; however, at their core, they all accomplish similar tasks, and, in most cases, use a stack structure โ€“ last in, first out.
The Xamarin.Forms navigation API uses stack-like terminology, closely resembling the navigation APIs of iOS. The Xamarin.Forms navigation API is exposed through the Xamarin.Forms.INavigation interface, which is implemented via the Navigation property that can be called from any Xamarin.Forms.VisualElement object. Typically, Xamarin.Forms.Page is the object used. Xamarin.Forms.NavigationPage also implements the Xamarin.Forms.INavigation interface and exposes public methods to perform common navigation tasks.
The Xamarin.Forms navigation API supports two types of navigation: standard and modal. Standard navigation is the typical navigation pattern where the user clicks or taps through a series of pages and is able to use either device/operating system-provided functionality (back buttons on Android and Windows), or app-provided elements (navigation bar on iOS and action bar on Android), to navigate back through the stack. Modal navigation is similar to the modal dialog concept in web apps where a new page is layered on top of the calling page, preventing interaction with the calling page until the user performs a specific action to close the modal page. On smaller form factor devices, modal pages typically take up the entire screen, whereas on larger form factors, such as tablets, modal pages may only take up a subset of the screen, more like a dialog. The Xamarin.Forms.INavigation interface exposes two separate read-only properties to view the standard and modal navigation stacks: NavigationStack and ModalStack.
The Xamarin.Forms.INavigation interface provides several methods to asynchronously push and pop pages onto the navigation ...

Table of contents

  1. Preface
  2. Getting Started
  3. MVVM and Data Binding
  4. Navigation
  5. Platform-Specific Services and Dependency Injection
  6. User Interface
  7. API Data Access
  8. Authentication
  9. Testing
  10. App Monitoring
  11. Other Books You May Enjoy
  12. Index