Using ReactiveCollection to monitor an existing collection...

331 views
Skip to first unread message

Dismantle

unread,
Mar 15, 2011, 11:36:41 AM3/15/11
to ReactiveUI mailing list
Hi there. I'm quite new to .NET Framework 4, Reactive extensions and
ReactiveUI, so please excuse me if my grasp of the concepts isn't
quite correct.

I was advised that using ReactiveCollection might solve a problem I'm
having in some front-end code, where UI elements aren't being updated
when an element in a particular collection of items changes.
OnCollectionChanged notifications fire if items are added to or
removed from this collection, but not when one of the items changes.
So, I wanted to declare a ReactiveCollection in my viewmodel to
monitor the collection and fire off notifications whenever there's any
change to it or it's items. I have a couple of questions about this...

1. Does this sound like a valid use of ReactiveCollection, and
2. Assuming the collection to be monitored implements IEnumerable<T>,
how do I pass my existing collection to CreateDerivedCollection? (This
has eluded me so far...)

The app uses a MVVM architecture, if that's relevant, and as mentioned
above, this ReactiveCollection will reside in the viewmodel, bridging
between the model and the view.

Again, apologies if I've somehow got the wrong end of the stick and
this isn't really a good use for ReactiveCollection - from what I've
read, I'm sure ReactiveUI will be very useful in other areas of the
UI :)

Thanks,
- Chris M.

Paul Betts

unread,
Mar 15, 2011, 12:12:21 PM3/15/11
to reacti...@googlegroups.com
> I was advised that using ReactiveCollection might solve a problem I'm
> having in some front-end code, where UI elements aren't being updated
> when an element in a particular collection of items changes.

ReactiveCollection can do this, but unfortunately WPF/SL doesn't know that
ReactiveCollection is able to do this, so it won't help you with updating
bindings. The feature you're referring to, is where you can Subscribe to
collection.ItemChanged (only once you've set ChangeTrackingEnabled to True!)

However, if all of the items in your collection have implemented
INotifyPropertyChanged, you usually don't have this problem, since WPF/SL will
handle listening to each of the child objects' INotifyPropertyChanged.

> 2. Assuming the collection to be monitored implements IEnumerable<T>,
> how do I pass my existing collection to CreateDerivedCollection? (This
> has eluded me so far...)

We can't create a derived collection from IEnumerable<T>, because there is no
way to tell when items change using the interface. Your collection has to be
an ObservableCollection<T> (or a derived class like ReactiveCollection).

> Again, apologies if I've somehow got the wrong end of the stick and
> this isn't really a good use for ReactiveCollection

No worries! Even if it's not currently a good use, one of the reasons I set up
the mailing list was to see what people are trying to do with RxUI and what
problems they run into, so I can see what *should* be in the framework.

Can you tell me a bit more about your scenario and what you're trying to do?
Maybe we can figure out why the controls aren't updating...

--
Paul Betts <pa...@paulbetts.org>

Reply all
Reply to author
Forward
0 new messages