Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

22. WPF Binding > Sorting Collections

Sorting Collections

Transforming raw data into something more useful or meaningful using a value converter is a good start on getting it into the form you need, but if you’re working with a collection, you’ll almost always want to specify the order in which the items are displayed. Even if your collection starts out that way, it’s going to get messed up as items are added and edited. Fortunately, the CollectionView lets you specify sort conditions by simply adding the appropriate properties to the SortDescriptions collection of the CollectionView.

image

Remember that CollectionViewSource is the XAML proxy for any kind of CollectionView. To set up sorting in XAML, you’ll need to declare the collection as a resource, create a CollectionViewSource element, and then bind to that (rather than directly to the collection):


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial


 Â