Get INPC from Model.

Oct 3, 2013 at 5:38 PM
Ok, I have the follwoing issue:

My model class is derived from ModelBase<T>, my ViewModel is derived from ViewModelBase<T>.

My model represents a person, therefore I have a lot of properties on that model class (as well as multiple sub classes with a ton of properties. Every property implements NotifyPropertyChanged.

In my ViewModel I create a property of the model which also implements NotifyPropertyChanged.
The view is bound to the property on the ViewModel.

Now if I change the values for, say the age, the NotifyPropertyChanged event gets raised in the Model, the VM has no idea that the property was changed, however I need the VM to know that one of the properties has changed to mark the person as edited and therefore enabling some buttons.

I could create a property for each and every property on the model and bind to those. This is really my last resort, since I have about 60 or so properties on the model.

The second Idea would be to use the MessageBus, but that seems kinda dirty to me.

Any ideas on how to solve this problem?
Oct 4, 2013 at 1:54 AM
One way you could do is to subscribe to the "PropertyChanged" event of the model. You could do this in the constructor of the Viewmodel.

Something like:
                  Model.PropertyChanged += FunctionSetModelAsDirty()

You could use the ViewModelDetailBase and pass the model so that you can make changes, save or discard the changes.
Oct 4, 2013 at 1:56 PM
Edited Oct 4, 2013 at 3:06 PM
ok, I think I'll stick with the ViewModelDetailBase way. However do I get it right from the documentation that I have to associate all properties from the model to the view model, or can I just call the BeginEdit/CancelEdit/EndEdit methods?

Could someone post me an example please?
Oct 7, 2013 at 3:37 AM

There is a example of this in the screencast that is available from the "Home" tab of this toolkit. It is the MVVM - Part 2 that links to:

You can start watching from about 34mins and the example for ViewModelDetailBase starts about 35mins into the screencast.

Please have a look at the Programming Reference in the documention tab as well.

Hope this helps.
Oct 7, 2013 at 5:04 PM
FYI, I may be discontinuing my subscription at - don't want to keep maying the monthly subscription. But the screencasts can still be downloaded from the links I have on the codeplex web site to Amazon S3. Cheers, Tony