New to WPF and also the ObservableCollection I need to sort it in my own way, and keep it sorted everytime something adds or removes from it.
ObservableCollection<User> users = new ObservableCollection<User>();
The user object is like so :
class User
{
public string Name { get; set; }
public bool IsOp { get; set; }
public bool IsAway { get; set; }
}
I would like all the IsOp's at the top of the list, in alphabetical order. Then all the non-ops in alphabetical order following them.
What is the correct way to achieve this?
Many thanks in advance.
The easiest way is to use a
CollectionView:When you will bind the view to that list, the items will appear in the specified order.
Using the trick shown here, you can even use Linq: