Data Binding To A ListView In Universal Windows Platform

I have written this code in blend for Visual Studio for design and for other animation purpose you can do this code in Visual Studio too.

Step 1: Make a Model Class of which you want to bind to a ListView,

  • To add class - Right click on your project, click Add, then New Item.

    new item

  • In the new item you will see code on the left, click it and click on class rename and click Add.

    class

For example, In this image I have made a model class of a Student with attributes Name, Class , Rollno and image,

student

Step 2: Make a ListView and add a container (Stack panel) to it and Textblock where you are going to populate your data.

Open the MainPage.xaml editor, you can add ListView by drag and drop from the toolbox or you simply Edit the xaml by adding the following code,

main

Here you can see in this image the textblocks Text Attribute binds with the properties of Student class.

Step 3: Now the final step is to add changes to your xaml.cs file,

  • Add an observable collection of student class.
  • Make a function that adds objects in the collection.
  • Provide the collection object to the list item source.

final

Up Next
    Ebook Download
    View all
    Learn
    View all