私はもともとこれを LINQ クエリとして投稿しました - 動作するようになり、問題があることに気付きました。LINQ クエリを使用して、CollectionViewSource 内のアイテムを選択/フィルター処理および順序付けすることはできません (なぜ最初にこれをチェックしなかったのか、なぜこれが可能でないのか?)。
そのため、フィルター処理された CollectionViewSource を並べ替える方法を見つけようとしています。
私の CollectionViewSource は ObservableCollection(Of MediaItems) にバインドされています。MediaItems には子/ネストされた List(Of AdvertOptions) が含まれます。
親 ObservableCollection(Of MediaItems) - クラスは次のように構成されています。
MediaItems
.ID (int)
.Src (string)
.Advert (bool)
.AdOptions As List(Of AdvertOptions)
.Counter (int)
AdvertOptions class consists of:
.Age (int)
.Gender (int)
.Priority (int)
次の基準を満たさない MediaItems を除外しています。
MediaItems.Advert = true
AdOptions.Age = x (parameter within triggered function called to perform the filter/sort)
AdOptions.Gender = y (parameter within triggered function called to perform the filter/sort)
CollectionViewSource がフィルター処理された後、2 つの並べ替え順序に基づいてアイテムを並べ替える必要があります。これにより、CollectionViewSource ナビゲーション メソッド (MoveCurrentToX など) を使用して、結果の CollectionViewSource アイテムをアプリケーション内でナビゲートできるようになります。
適用する必要がある並べ替え順序は次のとおりです。
- AdOptions.Priority (降順)
- カウンター別(昇順)
私がフィルタリングしている方法は、これらの関数を使用することです:
Public Shared Sub FilterByAdvertisement(ByVal Item As Object, ByVal e As FilterEventArgs)
Dim MediaObjectItem As MediaObject = TryCast(e.Item, MediaObject)
If Not MediaObjectItem.IsAdvertisingMedia = True Then
e.Accepted = False
End If
End Sub
Public Shared Sub FilterByAvertisementOption(ByVal Item As Object, ByVal e As FilterEventArgs)
Dim MediaObjectItem As MediaObject = TryCast(e.Item, MediaObject)
Dim Items = From m In MediaObjectItem.AdOptions Select m Where m.Age = Current.Age And m.Gender = Current.Gender
If Items.Count = 0 Then
e.Accepted = False
End If
End Sub
参考までに、次のようにフィルターを追加しています。
Public AdvertisingDataView As CollectionViewSource
AddHandler AppLocal.AdvertisingDataView.Filter, AddressOf FilterByAdvertisement
AddHandler AppLocal.AdvertisingDataView.Filter, AddressOf FilterByAdvertisementOption
フィルタリングされたアイテムをソートする方法を考え出す必要があります。問題は、CollectionViewSource での並べ替えのサポートが制限されているように見えることです。以下を使用してカウンターを簡単に並べ替えることができます。
AdvertisingDataView.SortDescriptions.Add(New SortDescription("Counter", ListSortDirection.Ascending))
しかし、それは私の 2 番目の並べ替えです。最初に AdOptions.Priority (適切な項目をサブ選択する必要があります) で並べ替え、次に Counter で並べ替えます。
グループを作成すると役立つかどうか疑問に思っていましたが、探している並べ替え機能が提供されるかどうかはわかりません。
CollectionViewSource の代わりに ListCollectionView に変換してから CustomSort を使用する可能性を検討しましたが、これを実装する方法がわかりません。ネストされたリスト内の値。
誰かが私の成果を達成するのを助けるために貢献できますか?
ベン