Data Binding in Xamarin.Forms - XAM270

Most apps need to load data from code-behind into their UI and transfer user-entered data to their code-behind models. Data Binding offers a clean way to perform both tasks. Data Binding uses binding objects that tie two properties together and keep their values in sync as either changes. This course shows you how to create bindings both in code and in XAML. You will also see how to implement value converters for use when the types of the two properties are different.

Upon completion you will be able to:

Course exercise download

Exercise materials are available from GitHub. The code can be cloned through a desktop Git client or downloaded directly as a ZIP file.

If you are using Windows, try to select a location with a shorter path length to make sure you don't exceed the 260 character limit.

Lecture

Here are the lecture slides.

Exercises

  1. Exercise 1: Using data binding in a Xamarin.Forms application (XAM270)

    This exercise introduces how you create and use bindings in code-behind and XAML.

  2. Exercise 2: Keeping the UI and data in sync using bindings (XAM270)

    In this exercise you'll implement two-way binding for your UI; this will ensure UI data changes are sent to the code-behind. You'll then implement INotifyPropertyChanged to ensure that the UI is updated when the underlying data is changed.

  3. Exercise 3: Using value converters (XAM270)

    There isn't always a 1:1 mapping between our available data and the user interface that presents that data. Value Converters are the bridge which spans this difference. In this exercise, you'll use a Value Converter to data bind images to our resources.

  4. Exercise 4: Homework: Abstracting out the shared code (XAM270)

    In this homework assignment, you will pull all the sharable code out of the code-behind now that it no longer depends on the UI controls and place it into a separate class which can be unit tested.

Additional resources

Additional Documentation

Data Binding Basics in Xamarin.Forms Type-safe PropertyChanged event handling in code (blog)