1

所以我手头确实有一个小问题,所以我有一个 Observablecollection 包含一些用户可以选择的项目,根据设置,列表可以按升序排序(新项目将在列表的底部)或降序(列表顶部的新项目)。现在,当列表变大(即:20 多个项目)时,我的问题出现了,应用程序变慢了。

所以我有一个功能,所以对列表进行排序

If Globals.isSorterenSelected Then
    If Globals.SorterenValue = "Ascending" Then
       Dim l As List(Of clsOrderItems) = (From o In OrderregelsGegroepeerd).OrderBy(Function(f) f.Gang).ThenBy(Function(f) f.item).OrderByDescending(Function(f) f.hoofdartikel).ToList
       OrderregelsGegroepeerd = New ObservableCollection(Of clsOrderItems)(l)
    Else
       Dim l As List(Of clsOrderItems) = (From o In OrderregelsGegroepeerd).OrderBy(Function(f) f.Gang).ThenByDescending(Function(f) f.hoofdartikel).OrderByDescending(Function(f) f.item).ToList
       OrderregelsGegroepeerd = New ObservableCollection(Of clsOrderItems)(l)

     End If
Else
    Dim l As List(Of clsOrderItems) = (From o In OrderregelsGegroepeerd).OrderBy(Function(f) f.Gang).ThenBy(Function(f) f.item).OrderByDescending(Function(f) f.hoofdartikel).ToList
    OrderregelsGegroepeerd = New ObservableCollection(Of clsOrderItems)(l)

End If

有没有其他方法可以对“OrderregelsGegroepeerd”进行排序,而不必重新创建整个 Observablecollection?

4

1 回答 1

1
'OrderregelsGegroepeerd = New ObservableCollection(Of clsOrderItems)(l)
 Dim NewIndex As Integer = 0
 For Each regel As clsOrderItems In l
     Dim idx As Integer = OrderregelsGegroepeerd.IndexOf(regel)
     OrderregelsGegroepeerd.Move(idx, NewIndex)
     NewIndex = NewIndex + 1
 Next

So that's the way i come up with, now i just have a small problem with the converter behind the new item but thats not a big deal! Thanks for the reply from keyboardP, that i actually only saw it before i figured the problem, but is still a good source of infomation.

于 2013-08-12T14:11:43.200 回答