【发布时间】:2014-02-08 09:34:00
【问题描述】:
我有一个在代码隐藏中绑定到集合的列表视图。 所以,当我按如下方式添加到集合中时:
collection.add(new CollectionItem());
ListView 已更新,一切正常。 但后来我想对集合进行排序:
collection = new ObservableCollection(collection.orderBy(key));
并且列表视图不会更新。 我尝试这样做:
sCollection = new ObservableCollection(collection.orderBy(key));
foreach(CollectionItem item in sCollection)
{
int oldIndex = collection.IndexOf(item);
int newIndex sCollection.IndexOf(item);
if (oldIndex!=newIndex))
{
collection.Move(oldindex,newIndex);
}
列表已更新,但滞后太多。它有大约 150 个元素,不多。 那么,当添加新项目时,对绑定集合进行排序和更新的最佳方法是什么?
【问题讨论】:
-
我认为你可以在collection改变后再次绑定listview。
-
这将重新创建视图元素的集合,它会滞后。
标签: c# xaml listview windows-store-apps