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 of type CollectionViewSource
and bouned to ObservableCollection as follows:
_ItemsViewSource.Source = Children;
Where Children is ObservableCollection. _ItemsViewsource is also bounded 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. In other words, I don't want to clear sorting but just disable it. How can I achieve this and preserve previous sorting? Thanks in advance.