PropertyObserver for ObservableCollection

Jul 22, 2009 at 2:04 PM

Hello

I am trying to find the best way to implement PropertyObserver for an ObservableCollection.

I got a ClipViewModel and a PlaylistClipModel and PlaylistCollectionViewModel.

The PlaylistClipModel got ObservableCollection<ClipViewModel>

The PlaylistCollectionViewModel got ObservableCollection<PlaylistClipModel>

Now i want to monitor if certain Properties in ClipViewModel got changed and fire that event in the corresponding PlaylistViewModel.

What is the best way to do that,

right now i am using Messenger to do that, eachplaylist got a Guid and i am adding this Guid each child element so each clip notify only his playlist rather than notifying all playlist.

Is there a better way using PropertyObserver.  Do u think add a PrepertyObserver for each ClipViewModel is better.

 

BR

Shahbour

Coordinator
Jul 22, 2009 at 5:20 PM

Charles Petzold tackled this problem in an MSDN Magazine article: http://msdn.microsoft.com/en-us/magazine/cc794276.aspx#id0070059

Jul 22, 2009 at 6:12 PM
Edited Jul 22, 2009 at 6:40 PM

Thanks, it is exactly what i need.

I only changed

 

public ItemPropertyChangedEventHandler ItemPropertyChanged;

into
public event ItemPropertyChangedEventHandler ItemPropertyChanged;

in ObservableNotifiableCollection Class

I think it should be an event right ?

BR
Shahbour

 

Aug 13, 2009 at 8:39 PM

Great link to the Petzold article -- it helped me solve the same issue of monitoring item property changes within an ObservableCollection Just wanted to post a follow-up link from Petzold's blog:

http://www.charlespetzold.com/blog/2008/09/My-Article-on-Property-Changed-Notifications-in-MSDN-Magazine.html

The ObservableNotifiableCollection that Petzold details in his original article (that Josh posted the link to above) does not correctly remove event handlers for items that are removed from the collection via Clear(). The above link has Petzold's fix for that: overriding the ClearItems() method in ObserableNotifiableCollection to ensure the event handlers are correctly removed.

Shahbour, I agree with you -- I think there should be an event keyword there as well, although it seems to work fine without it.

Ken