0
我有一個列表視圖綁定到代碼隱藏的集合。 所以,當我添加到集合新項目如下:Windows應用程序列表視圖更新
collection.add(new CollectionItem());
ListView控件進行更新,並一切正常。 但後來我要排序的集合:
collection = new ObservableCollection(collection.orderBy(key));
和ListView不`噸更新。 我試圖做到這一點,如下所示:
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個元素,而不是更多。 那麼,添加新項目時,排序和更新綁定集合的最佳方法是什麼?
我認爲你可以在收集改變後再次綁定listview。 –
這將重新創建視圖元素的集合,它會滯後。 –