text: , >
  using System; using System.Collections.Generic; using System.Windows; namespace WpfTutorialSamples.ListView_control { public partial class ListViewDataBindingSample : Window { public ListViewDataBindingSample() { InitializeComponent(); List<User> items = new List<User>(); items.Add(new User() { Name = "John Doe", Age = 42 }); items.Add(new User() { Name = "Jane Doe", Age = 39 }); items.Add(new User() { Name = "Sammy Doe", Age = 13 }); lvDataBinding.ItemsSource = items; } } public class User { public string Name { get; set; } public int Age { get; set; } } }
  We populate a list of our own User objects, each user having a name and an age. The data binding process happens automatically as soon as we assign the list to the ItemsSource property of the ListView, but the result is a bit discouraging:
  Each user is represented by their type name in the ListView. This is to be expected, because .NET doesn't have a clue about how you want your data to be displayed, so it just calls the ToString() method on each object and uses that to represent the item.
  We can use that to our advantage and override the ToString() method, to get a more meaningful output. Try replacing the User class with this version:
  public class User { public string Name { get; set; } public int Age { get; set; } public override string ToString() { return this.Name + ", " + this.Age + " years old"; } }
  This is a much more user friendly display and will do just fine in some cases, but relying on a simple string is not that flexible. Perhaps you want a part of the text to be bold or another color? Perhaps you want an image? Fortunately, WPF makes all of this very simple using templates..
  <Window x: <Grid> <ListView Margin="10" Name="lvDataBinding"> <ListView.ItemTemplate> <DataTemplate> <WrapPanel> <TextBlock Text="Name: " /> <TextBlock Text="{Binding Name}" FontWeight="Bold" /> <TextBlock Text=", " /> <TextBlock Text="Age: " /> <TextBlock Text="{Binding Age}" FontWeight="Bold" /> <TextBlock Text=" (" /> <TextBlock Text="{Binding Mail}" TextDecorations="Underline" Foreground="Blue" Cursor="Hand" /> <TextBlock Text=")" /> </WrapPanel> </DataTemplate> </ListView.ItemTemplate> </ListView> </Grid> </Window>.