Introduction

In Visual Studio 2017, we can develop Cross Platform apps, using Xamarin. Xamarin is a platform to develop apps for multiple mobile operating systems by a shared code base. In Xamarin, we can develop separate UI apps or shared UI apps. Shared UI apps are developed through Xamarin forms.

In this article, we will do some data binding in xamarin.forms.

Target audience

Beginners with basic C# and XAML coding knowledge.

Technical requirements

Installation

Download Visual Studio Installer from here (https://www.visualstudio.com)

You can install Visual Studio 2017 with Xamarin workload.

Data binding

Data binding is the process, which establishes a connection between the Application user interface and an Application logic. We may bind the data with the elements and if binding is done correctly, it can reflect changes automatically.

Data Binding

The main benefit of Data binding is that you no longer have to worry about synchronizing the data between your views and data source.

Binding has several properties including.

Binding Path

Path is used to specify property name of the source object, which is used for binding.

Binding Mode

Mode is used to provide the direction in which property value changes are made.

Binding example

Here, we can link properties of two views on a single page.

Let’s go through its example,

XAML

  1. <StackLayout>
  2. <Slider x:Name="slider" Maximum="360"></Slider>
  3. <Label Text="Rotation"
  4. BindingContext="{x:Reference Name=slider}"
  5. Rotation="{Binding Path=Value}"
  6. HorizontalOptions="CenterAndExpand"
  7. ></Label>
  8. </StackLayout>

Here, we bind the value property of slider with rotation property of the label with Oneway binding, which is set by default, so, when we move the slider, label starts rotating and maximum value of slider is set to 360.

Output on an Android and Windows desktop is given below.

Data Binding In Xamarin.Forms