views:

1009

answers:

2

Is there a way to filter/sort an observable collection and still keep the notifications?

I have looked around and I found CollectionViewSource which filters and sorts the collection as I require but when the an items property in which the filter relies changes at the source collection it does not refresh the filter.

Basically i require a view of the original collection that when a property of an item in the view changes it updates the source and when the source changes it updates the view. Is there any class that provides this functionality in silverlight 3?

A: 

Does ObservableCollection with TwoWay binding not work? Can you elaborate your example with some code to show the issue in more detail?

Mark Cooper
A: 

I would suggest using the Bindable.Linq library, it hasn't been updated for a while and there is a bug with the Union operator. But for linq style filters it works great.

heres a quick example, assuming this is in the codebehind of a silverlight user control with a listbox named people:

using Bindable.Linq;
...

ObservableCollection<Person> data = new ObserableCollection<Person>{.... fill in};
people.ItemsSource = data.AsBindable(Dispatcher).Where(p => p.FirstName.Equals("steve"));
data.add(new Person("steve"));

if you do this steve should show up on the list. I have found this library very useful and if you download the sample projects from codeplex it shows more advanced examples.

Hope this helps.

There are several other similar projects

luke