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.
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 theContent
tag, add the following code that adds two Label controls:<StackLayout HorizontalOptions="Center" VerticalOptions="Center"> <Label x:Name="firstNameLabel" /> <Label x:Name="lastNameLabel" /> </StackLayout...