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…
- 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
. - In the
XamFormsCodeBinding
PCL library, right-click and choose Add | Class…; give it the namePerson.cs
and click Add. - 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; } }
- Right-click
XamFormsCodeBinding
PCL and Add | New Item…; choose Forms Xaml Page, name itMainPage.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.