Binding data in code

This recipe introduces the concept of data binding: binding properties of an object (source) to the view controls (target) in the behind code of a page.

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 XamFormsCodeBinding.
  2. In the XamFormsCodeBinding 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 XamFormsCodeBinding PCL and Add | New Item…; choose Forms Xaml Page, name it MainPage.xaml, and click Add. In ...

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.