Sort ListBox in WPF

Let me start by saying that I am completely new with WPF (this is my first project and I have been working in it for less than a week). With that said, please be calm!

I have three ListBoxes lists that are tied to ObservableCollectionfrom LINQ queries. In the beginning, everything is fine, all three are filled correctly. My client must drag the selection from one ListBoxto another. I also have this job, but when I do a drag and drop, a new selection is placed at the bottom ListBoxinstead of sorting alphabetically with existing elements.

How can I sort ListBoxat runtime through code after the drag and drop operation is complete.

Thanks!

+3
source share
1 answer

It's not entirely clear how you handle code drag and drop. You are saying that your ListBoxes are data bound, which means that you are actually moving items from one fallback collection to another when you drag and drop. If so, the ListBox simply displays the items so that they are present in the collection. You must either sort them there, or if sorting is view-only behavior in your case (i.e., the elements are actually disordered in the data model, by design), you must use them CollectionViewto wrap your collections, set them up sort and bind to them lists of ListBoxes.

+5
source

Source: https://habr.com/ru/post/1713273/


All Articles