问题
I have a collection that is binded to my Listview.
I have provided options to user to "move up" "move down" the selected item in the list view. I have binded the selected item of the listview to my viewmodel, hence I get the item in the collection on which user want to do the operation.
I have attached "move up" "move down" commands in my viewmodel.
I want what is the best way to move up and down in the collection in the collection which is reflected in the list view.
For example
If the selected item is the last item in the collection ( and in the list view) move the item to the top.
For this I have to create a new collection and reorder the items in the collection.
Please suggest.
回答1:
You can do this by retrieving the index of the ObservableCollection corresponding to the selected item and swapping it with the previous item.
来源:https://stackoverflow.com/questions/2620091/how-to-traverse-the-item-in-the-collection-in-a-list-or-observable-collection