DataBinding and It's Modes in UWP

Data Binding

Data Binding is the process of establishing a connection between the user layer and data layer.Whenever you change the user layer the data layer also changes.

Advantage of Data Binding

By using data binding you can build enterprise level applications easily.You can save your time by using data binding in your applications.You can call consume API (application programming interface) just by using data binding. Data binding is also very helpful in RSS Feeds and WebScrapping.

There are two common modes of data binding:

  1. One Way DataBinding
  2. Two Way DataBinding

 

Oneway is a most common mode of data binding. In one way mode when we change the source then target also changes but when we change the target then there's no change on source However in two way mode when we change any one of these two there's an effect on both; i.e., source changes target and target changes source.

Let's try it with an example.

Step 1: First we'll create an Empty Blank Universal Windows Project and name it whatever you want.



Step 2: 
Next to this we'll add two TextBoxes in StackPanel.We'll give a name onewaytxt to our second textbox and bind the text property of second textbox with first textbox by providing Text binding property.However the only difference we'll do in two way databinding is by providing the Mode property i.e., Mode = TwoWay.



Step 3: 
Now run your application and type some text i the first textbox and you'll notice there's no change onthe second textbox because thesecond textbox is our source and we can't change the source by changing our target.However if we change the target i.e., second textbox, then the text in first textbox will definitely change.

 

Now let's talk aboutthe second scenario that is two way data binding. It's opposite to the first one i.e., when ever you change the text in source textbox then target changes and when you'll try to change the target textbox then source will also changes.

Run

 

Ebook Download
View all
Learn
View all