How to traverse the item in the collection in a List or Observable collection?

主宰稳场 提交于 2019-12-25 03:42:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!