Skip to content

Sorting a ListBox of ListItems the WPF Way

by karlkatzke on September 1st, 2010

Sorting a ListBox the C# WinForms way:

lstFooBar.sort = "true";

Sorting a ListBox the C# 4.0 Widows Presentation Foundation way:

lstFooBar.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("Content", System.ComponentModel.ListSortDirection.Descending));

… this is an improvement?!

Note: You can also do this in the XAML. I haven’t tested it, but it’d look something like:

<CollectionViewSource.SortDescriptions>
   <dat:PropertySortDescription Direction="Descending" PropertyName="Content" />
</CollectionViewSource.SortDescriptions>

From → .Net, C#, WPF

No comments yet

Leave a Reply

Note: XHTML is allowed. Your email address will never be published.

Subscribe to this comment feed via RSS