DataBinding using MVC in UWP

Step 1: First of all create a New Universal Windows Project in Visual Studio 2015.



Step 2: 
After this create a class into your project by right clicking on your project and Add Class and name it whatever you want. After this add two properties in your class.This class is our Model.



Step 3: 
After the successful creation of your model we will create a View in MainPage.xaml.For that purpose we will need a listbox and in this list box we'll add itemtemplate and datatemplate and between these we'll add some textblocks and bind the Text property of textblock with our class methods. We'll also bind the itemsource of our listbox to the Model class name.

Step 4: Now it's time to move on to the controller section of our appliction.For this purpose we create a simple function and in this function we'll create an instance of a List with our class object. We'll declare two arrays; one for holding our rollnumbers and the other is for holding our names.Now we can add a for loop and create an object of our Model Class and call the properties of our Model Class and assign an array value to these.Now we can add the Model Class object to our list by using s.Add(s1) ;

After this we can assign this List object to the listbox itemsource.


Step 5: The most important thing is now we'll call this function in our MainPage constructor.



Step 6: 
Now run your application by pressing F5 and you'll notice that we've successfully bind a ListBox to the model and controller.

Ebook Download
View all
Learn
View all