Sorting and filtering bound collections

Data templates provide a powerful way to present data using text, images, and anything else WPF is capable of. Often, we need to present the data in some order, typically sorted by some property (or properties). Sometimes we don't want to show all data, but a part of it, such as when a user searches for something and we want to show the result of the search, which maybe just a subset of the original data.

One way to go about it is to operate on the data itself. We can certainly apply sorting on lists (List<T>.Sort, Array.Sort, and so on), as well as filtering (List<T>.FindAll), and by using Language Integrated Query (LINQ) it's even easier (and more versatile) to sort (orderby clause) and/or filter (where ...

Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.