Windows Presentation Foundation (WPF) Question:

How elements in a ListBox sorted?

Tweet Share WhatsApp

Answer:

Sorting can be done by using a property of the ItemsCollection object. ItemsCollection contains an attribute, SortDescriptions, which holds System.ComponentModel.SortDescription instances. Every SortDescription instance defines how the elements should be sorted and indicates if the sort is descending or ascending.

For instance, this code sorts elements of ContentControl on the basis of their word count property:
myItemsControl.Items.SortDescriptions.Add(new SortDescription("WordCount", ListSortDirection.Descending));

Download WPF PDF Read All 57 WPF Questions
Previous QuestionNext Question
List the types of windows in WPF?Explain the difference between MVVM and MVC?