Binding data in XAML

This recipe introduces the concept of data binding some object instance properties to view controls in XAML.

How to do it…

  1. Start by creating a Visual Studio Blank App (Xamarin.Forms Portable) solution. In the top menu, click File | New | Project… and give it the name XamFormsXamlBinding.
  2. In the XamFormsXamlBinding PCL library, right-click and choose Add | Class…; give it the name Person.cs and click Add.
  3. Copy the following code to add two simple properties in Person.cs:
    public class Person
    {
      public string FirstName { get; set; }
      public string LastName { get; set; }
    }
  4. Right-click the XamFormsCodeBinding PCL and Add | New Item…; choose Forms Xaml Page, name it MainPage.xaml, and click Add. In the Content tag, add the following code ...

Get Xamarin: Cross-Platform Mobile Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.