WPF ItemsViewSource Sorting

Posted by niao on Stack Overflow See other posts from Stack Overflow or by niao
Published on 2010-03-30T07:39:29Z Indexed on 2010/03/30 7:43 UTC
Read the original article Hit count: 667

Filed under:
|

Greetings, I have a problem with sorting ItemsViewSource in WPF. The problem is as follows: My application has a listbox with items, there is a possibility to add new items to this listbox. I have ItemsViewSource which is binded to ListBox ItemsSource - by default some sortDescription is applied (by name) so when new item is added to the listbox it is automatically added to appopriate position in ListBox. I also have a ToggleButton named "No sorting" and what I would like to achieve - when this butt is pressed and new item is added to listbox, the item will be included in the first position in ListBox and additionally previous sorting will be preserved. I can achieve the functionality of adding new item to first position on the list by calling

_ItemsViewSource.SortDescriptions.Clear();

but then my previous sorting is not preserved. How can I achieve this and preserve previous sorting? Thanks in advance.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about sorting