XAML Data Binding - XAML

What is XAML Data Binding?

Data binding is a mechanism in XAML programs that offers a easy and easy way for windows Runtime Apps using partial classes to show and interact with information. The control of data is entirely separated from the way the data is displayed in this mechanism.

Data binding permits the flow of data among UI elements and information item on user interface. when a binding is established and the data or your business model adjustments, then it will reflect the updates automatically to the UI elements and vice versa. it is also possible to bind, not to a general information source, but rather to another element at the page. facts binding may be of types −

  • One-way data binding
  • two-way data binding

One-Way Data Binding

In one-way binding, data is certain from its source (that is the item that holds the information) to its target (that is the item that shows the data).

Let’s have a look at a easy example of one-manner information binding. the following XAML code creates four text blocks with a few properties.

Text properties of two text blocks are set to “name” and “title” statically, even as the other text blocks text houses are sure to “call” and “title” which are class variables of employee class which is shown below.

In this class, we have just two variables, Name and Title, and one static technique in which the employee item is initialized for you to return that employee object. So we are binding to a assets, name and title, but we have not selected what item that assets belongs to. the easiest manner is to assign an item to DataContext whose properties we are binding in the following C# code –

Let’s run this application and you may see at once in our MainWindow that we have correctly bound to the call and title of that employee object.

XAML - Data Binding

Two-way Data Binding

In -manner binding, the person can adjust the information through the person interface and have that information updated within the source. If the source changes while the user is calling at the view, you would want to update the view.


Let’s have a look at the following example in which one combobox with three combobox items and one textbox are created with a few properties. In this example, we don’t have any standard information source, but the UI elements are bound to other UI elements.

When you collect and execute the above code, it will produce the following output. when the user selects an object from the combobox, the textbox text and the background color will be updated accordingly.

XAML - Data Binding

Similarly, while the user types a valid color name in the textbox, then the combobox and the textbox background color will also be updated.

XAML - Data Binding

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

XAML Topics