5

I have a few sources that expose an ObservableCollection<MyData> property. Now I want to bind ListBox.ItemsSource to all of them and support CollectionChanged notifications, sorting and filtering. How to do that? CompositeCollection doesn't support filtering.

Poma
  • 8,174
  • 18
  • 82
  • 144
  • Do you mean you want to bind to all of the sources at once and receive updates from them all (MultiBinding - http://msdn.microsoft.com/en-us/library/system.windows.data.multibinding.aspx) or you want to bind to multiple sources and receive updates from the first that responds (PriorityBinding - http://msdn.microsoft.com/en-us/library/system.windows.data.prioritybinding.aspx) – dash Oct 25 '12 at 11:51
  • 1
    I want to display flattened list from all collections and receive changes from all of them. – Poma Oct 25 '12 at 11:58
  • Possible duplicate: http://stackoverflow.com/questions/11288/wpf-sorting-a-composite-collection – Joe Oct 25 '12 at 19:45

1 Answers1

0

You can use CompositeCollection and CollectionViewSource together.. use CompositeCollection to combine all collections and later create a collection view source from that CompositeCollection. You can use filter properties in CollectionViewSource

Look Here for Sample

How to handle a CompositeCollection with CollectionView features?

Community
  • 1
  • 1
Bathineni
  • 3,436
  • 18
  • 25
  • Nope. `'MS.Internal.Data.CompositeCollectionView' view does not support filtering.` – Poma Oct 25 '12 at 11:56
  • @Poma - Take a look at the sample. Create a CompositeCollection and then use it as the source of a CollectionViewSource (which suopports filters). – Joe Oct 25 '12 at 12:58
  • @JonathanPiché no it isn't. `new CollectionViewSource { Source = new CompositeCollection() }.View.CanFilter == false` – Poma Oct 25 '12 at 13:19
  • Did you try to use the CollectionViewSource.Filter directly instead of going through ".View"? – Joe Oct 25 '12 at 13:22
  • Use BindingListCollectionView's CustomFilter: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/49844e5f-0fc5-4bdd-8506-e1d71124ed08 – Joe Oct 25 '12 at 15:09
  • @Joe tied code from your example. Got exception `Unable to cast object of type 'MS.Internal.Data.CompositeCollectionView' to type 'System.Windows.Data.BindingListCollectionView'.` – Poma Oct 25 '12 at 19:14