My View (V) is bound to a ViewModel (VM). In the V I have a List of objects that is displayed in a ListView. In the ListView I use an ItemTemplate, each item is displayed as a Label holding the name of the item and a Combobox with the SelectedItem set to another property of the item. The Combobox is bound to a List which is also part of the VM of the main V (I bind it using ElementName=ListBox.DataContext in the Binding...)
So far everything works very well. The problem is that the Combobox can contain a lot of entries and I would like to use grouping or filtering. I know how to use filtering and grouping using ListCollectionView. But I cannot simply change my List to a ListCollectionView since it is used multiple times (for each item in the ListView). One ListCollectionView cannot be used multiple times but have different SelectedItem for each usage.
Now I am looking for an easy way to use grouping in the ListView's Combobox.
Is there a way to define the ListCollectionView directly in XAML inside the ItemTemplate (DataTemplate)? I also thought about using a (non-shared) Converter in the ItemsSource Binding that converts my List of objects into a ListCollectionView (if I use OneTime Binding, the Converter will only be called once, is that correct?)? I know I could also put each object in the List in the VM in its own ViewModel and each of it provides its own ListCollectionView for the Combobox, but that seems to be the most complicated solution (but maybe the cleanest?)
Any other suggestions or advice?
If you want to use the same ICollectionView
in multiple comboboxes (or other selectors) without synchronizing their selected item, you need to explicitely set IsSynchronizedWithCurrentItem="False"
on each combobox.