C# windows应用商店应用程序列表视图更新
我有一个在代码隐藏中绑定到集合的listview。 因此,当我向集合中添加新项时,如下所示:C# windows应用商店应用程序列表视图更新,c#,xaml,listview,windows-store-apps,C#,Xaml,Listview,Windows Store Apps,我有一个在代码隐藏中绑定到集合的listview。 因此,当我向集合中添加新项时,如下所示: collection.add(new CollectionItem()); sCollection = new ObservableCollection(collection.orderBy(key)); foreach(CollectionItem item in sCollection) { int oldIndex = collection.IndexOf(item); int newIn
collection.add(new CollectionItem());
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);
}
ListView已更新,一切正常。
但接下来我想对集合进行排序:
collection = new ObservableCollection(collection.orderBy(key));
并且listview不会更新。
我试着这样做:
collection.add(new CollectionItem());
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个元素,而不是更多。
那么,当添加新项目时,排序和更新绑定集合的最佳方式是什么呢?它会滞后,因为如果你想短缩150个项目,然后更新它。 我认为,如果你使用更少的内存或轻巧的代码,你可以解决这个问题,我的意思是你可以使用更难一点但更好的算法来解决这个问题,或者你可以使用许多不同的方法,比如添加线程。Sleep10;,但是你的电脑小吗? 如果是,在另一个系统上尝试,祝你好运
关于我认为可以在集合更改后再次绑定listview。这将重新创建视图元素集合,它将延迟。