Windows Presentation Foundation (WPF) Question:

Download Job Interview Questions and Answers PDF

How elements in a ListBox sorted?

WPF Interview Question
WPF Interview Question

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 Interview Questions And Answers PDF

Previous QuestionNext Question
List the types of windows in WPF?Explain the difference between MVVM and MVC?