The Data Binding feature in ListView control helps to update the data on the ListView UI by reducing the code size. The ItemsSource property is used to specify the data source that the ListView control will be bound to.
The below section discusses bound ListView in detail.
Create a simple class Products to hold data items.
Initialize a list in the MainWindow constructor, and add the items to it, and assign the list to the ItemsSource of the ListView.
C# |
Copy Code
|
---|---|
public List<Product> Products { get; set; } |
Create the code snippet as given below between the grid tags:
You can observe from the code above how a template has been declared that will be used to render each item in the UI.
Run the code and see the populated data in the listview items.