Posts

Showing posts with the label ItemsSource

Binding data to ListView controls in WPF using MVVM

Image
Some few tips and instructions on how to bind data items contained in a List to a WPF ListView. Create a new empty WPF Application: Then create a new ViewModel class for out MainWindow.xaml which will be used to create and access the data items that are bound to the ListView: Our MainWindowViewModel class has a getter for obtaining the list of data items we wish to present in the ListView control: MainWindowViewModel.cs [code language="csharp"] using System.Collections.Generic; namespace ListViewWpf { public class Item { public Item(string name, string matches) { Name = name; Matches = matches; } public string Name { get; set; } public string Matches { get; set; } } public class ItemHandler { public ItemHandler() { Items = new List<Item>(); } public List<Item> Items { get; private set; } public void Add(Item item) { Items.Ad...