I have a ListView in my XAML:
<ListView Margin="10" Name="lvDataBinding"></ListView>
In the code I have User class:
public class User
{
public string Name { get; set; }
public int Age { get; set; }
public override string ToString
{
return this.Name + ", " + this.Age + " years old";
}
}
and code that binds the collection of Users to ListView:
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 });
items.Add(new User() { Name = "Any Dam", Age = 90 });
lvDataBinding.ItemsSource = items;
Now I want to sort the data in ListView by User.Name or User.Age. How can I do it ?