Developer's Academy: Sample Data Binding in Windows Store 8.1 App

Wednesday, 28 January 2015

Sample Data Binding in Windows Store 8.1 App

In this tutorial i will explain how to bind an element at run time. Before going into the development let me explain theoretically what i am going to achieve in this tutorial.

First i will add a TextBox and a TextBlock. I will bind the text property of TextBlock with the TextBox. At the backend code i am implementing an interface IValueConverter which will show the remaining number of characters in the TextBlock.

Following are the steps to implement this:

1) Open Visual Studio 2013 and create a new project of Windows Store Apps.
2) Create a blank app and name it SimpleBinding.
3) Add a StackPanel inside a Grid and add one TextBox and one TextBlock.
4) Name the TextBox as "txtBox".
5) Right Click on the project and add a new class and name it as "RemainingCharacters.cs"
6) Implement the "IValueConverter" interface by resolving it with its namespace "using Windows.UI.Xaml.Data".
7) Implemenet the "Convert" and "ConvertBack" methods of the interface.

RemainingCharacters.cs


8) Open MainPage.Xaml and add the following code before Grid.


9) Finally, we have to bind the TextBloxk's Text property to show the remaining characters. 

MainPage.Xaml


Final Output


No comments:

Post a Comment