Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Mastering Xamarin.Forms
Mastering Xamarin.Forms

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

eBook
$22.99 $25.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Mastering Xamarin.Forms

Chapter 2. MVVM and Data Binding

In this chapter, we will look at the Model-View-ViewModel (MVVM) pattern and the MVVM elements that come with the Xamarin.Forms toolkit, and how we can expand on them to truly take advantage of the power of the pattern. As we dig into these topics, we will apply them to the TripLog app that we started building in Chapter 1, Getting Started.

In this chapter, we will cover the following:

  • Understanding the MVVM pattern and data binding
  • MVVM in the Xamarin.Forms toolkit
  • Adding the MVVM pattern and data binding to the Xamarin.Forms mobile app created in Chapter 1, Getting Started

Understanding the MVVM pattern

At its core, MVVM is a presentation pattern designed to control the separation between user interfaces and the rest of the application. The key elements of the MVVM pattern are as follows:

  • Models: Models represent the business entities of an application. When responses come back from an API, they are typically deserialized to models.
  • Views: Views represent the actual pages or screens of an application, along with all of the elements that make them up, including custom controls. Views are very platform-specific and depend heavily on platform APIs to render the application's user interface (UI).
  • ViewModels: ViewModels control and manipulate the Views by serving as their data context. ViewModels are made up of a series of properties represented by models. These properties are part of what is bound to the Views to provide the data that is displayed to users, or to collect the data that is entered or selected by users. In addition to model-backed properties...

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...

Summary

In this chapter, we updated the app that we started creating in Chapter 1, Getting Started, by removing data and data-related logic from the pages, off-loading it to a series of ViewModels, and then binding the Pages to those ViewModels. In the next chapter, we are going to expand on Xamarin.Forms navigation service, so that we can also move navigation code from the views to the ViewModels.

Left arrow icon Right arrow icon

Key benefits

  • • 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

Description

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.

Who is this book 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

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 30, 2016
Length: 184 pages
Edition : 1st
Language : English
ISBN-13 : 9781785287190
Vendor :
Microsoft
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jan 30, 2016
Length: 184 pages
Edition : 1st
Language : English
ISBN-13 : 9781785287190
Vendor :
Microsoft
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 81.98
Mastering Xamarin.Forms
$32.99
Mastering Cross-Platform Development with Xamarin
$48.99
Total $ 81.98 Stars icon

Table of Contents

10 Chapters
1. Getting Started Chevron down icon Chevron up icon
2. MVVM and Data Binding Chevron down icon Chevron up icon
3. Navigation Service Chevron down icon Chevron up icon
4. Platform Specific Services and Dependency Injection Chevron down icon Chevron up icon
5. User Interface Chevron down icon Chevron up icon
6. API Data Access Chevron down icon Chevron up icon
7. Authentication Chevron down icon Chevron up icon
8. Testing Chevron down icon Chevron up icon
9. App Analytics Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(11 Ratings)
5 star 45.5%
4 star 18.2%
3 star 27.3%
2 star 9.1%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Jeff B Jun 28, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I love seasoned developer-centric books like this. I know C# like the back of my hand but have never used Xamarin and that's exactly who this book is for. This is no introduction to C#, development concepts or object oriented programming, look elsewhere to get up to speed on those concepts first. But if you're an able C# developer this book rules for getting up to speed quickly on Xamarin. There is minimal overview and tons of "let's just do it" chapters. I'm amazed how quickly I was up and running with a functional cross-platform app. Yes, you have to look up anything you don't understand elsewhere, just keep a web browser handy. I had to get up to speed on dependency injection and unit testing which were new to me, but easy enough to comprehend. Again, not for newbies by any means but a great book if you know C# and basic OO already.My only complaint and it's nit picky is I wish the downloadable code had snapshots for each chapter. The code you download is as of the end of the book and the code evolves considerably over the course of the book so cutting and pasting becomes tricky early on if you want to avoid typing in some of the lengthier sections. You can cut and paste from the Kindle edition for a while, but eventually you run out of chances as the publisher sets a cut and past limit.Still highly recommended.Jeff
Amazon Verified review Amazon
S. Chowdhuri Oct 21, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As Xamarin grows in popularity, new books on Xamarin (especially Xamarin.Forms) are hard to come by as each of the platforms are changing rapidly, as is Xamarin. Ed Snider, who I've known as a Xamarin MVP in my region for quite a while now, excels as a developer, public speaker, community leader and technical author.I would highly recommend this book to anyone looking to master Xamarin.Forms! :-DShahed ChowdhuriSr. Technical Evangelist @ Microsoft
Amazon Verified review Amazon
M. Feb 10, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
So maybe you know some c#. Maybe you used to do WPF or Silverlight, and are looking to start working on the mobile platforms. Maybe you know iOS or Android and are looking at this cross-platform thing. Or maybe you are like me and know "Classic Xamarin" pretty well and have been looking for an excuse to learn Xamarin Forms. Well, look no further.There is a ton of information out there on the internet about Xamarin and Xamarin.Forms - and programming in general. Most of it us uncurated, so I typically turn to a book to get a head start. On this topic, I read the introductory book (Creating Mobile Apps with Xamarin.Forms by Petzold) and found it to be a bit too introductory for me. This book however was great at taking some of the patterns we all know and love (like navigation, and MVVM) and showing how to execute them in real world examples. Exactly what I needed to get proficient quickly. It will be a good reference to have on the shelf.
Amazon Verified review Amazon
ppfeifer Oct 17, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book was exactly what I was looking for. It gets into the meat of things quite quickly, which is nice to get a feel for the capabilities of Xamarin.forms.
Amazon Verified review Amazon
Brandy Mehaffey Apr 02, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Author definitely knows what he is talking about.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.