如何遍历List或观察的集合集合中的项目? [英] How to traverse the item in the collection in a List or Observable collection?

查看:234
本文介绍了如何遍历List或观察的集合集合中的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到我的列表视图的集合。

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.

例如

如果选定的项目是集合中的最后一个项目(在列表视图)移动的项目到顶部。

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.

请建议。

推荐答案

您可以通过检索对应于所选项目的ObservableCollection的指标,并与previous项目交换它做到这一点。

You can do this by retrieving the index of the ObservableCollection corresponding to the selected item and swapping it with the previous item.

这篇关于如何遍历List或观察的集合集合中的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆