views:

43

answers:

1

I am writing a sample app in WPF and I'd like the Model to be easily reusable in a WinForms app so I'd like to keep WPF specific stuff like INotifyChanged and DependencyObjects out of it.

If a Model class has a List of some other Model class, how do I implement the corresponding ObserveableCollection in the View-Model so I can keep my bindings up to date?

A use case for this would be if I have a Boss model object who has a list of Employee's. I create a Boss object, but I load the list of Employees asynchronously, how do I know when the list of Employees has been retrieved and populated? I would like to keep the loading code inside of the Model.

I suppose to summarize what I'm asking is what's the proper way to have Model to Model interactions whilst having the View-Model reflect these changes?

+3  A: 

Your model will need to provide change notifications. You can do so in an agnostic fashion by using INotifyPropertyChanged and INotifyCollectionChanged. Contrary to your question, these are not WPF-specific interfaces. They are in System.ComponentModel - not a WPF namespace or assembly.

If you really don't want to use those interfaces, then you can always provide your own events. Whatever the case, your view model will need to attach to events to keep itself up to date with your model.

HTH,
Kent

Kent Boogaart
Thanks, I was hoping there was some other pattern to do it but it would appear not. Also I suppose I always just associate INotifyPropertyChanged with WPF because its used so heavily there!
Brent Barkman