开发者

Silverlight 3 - Filtering an Observable Collection

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

I have looked around and开发者_如何学Go 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?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜