Validate/Notify derived model properties change

Apr 23, 2012 at 6:20 AM
Edited Apr 23, 2012 at 6:22 AM


I have a situation. Please let me know if there is a better way to do this.

  • I have created my own MyBaseModel<TModel> which derives from ModelBase<MyBaseModel<TModel>>
  • I now get Property changed and validation for the its properties. Great!
  • Now I have to create models that derive from MyBaseModel as they have common properties declared in MyBaseModel. Lets call them childModels
  • But now I don't get the support for NotifyPropertyChanged or the ValidateProperty for its properties.

As a workaround,

  • I created a property in MyBaseModel of type <TModel> [let call this property "Self"]
  • In the viewmodel, when I create a childModel, I assign the childModel to this property of type<TModel>
  • Since, MyBaseModel<TModel>: ModelBase<MyBaseModel<TModel>>, I can get the property changed and validation working for childModel properties by calling - NotifyPropetyChanged(m => m.Self.AnyProperty)

Is there a better way to call property change and validation in childModels?

Many thanks for viewing this post!

Apr 23, 2012 at 8:39 AM
Edited Apr 23, 2012 at 8:41 AM


One better solution I got was using Virtual properties and abstract methods in MyBaseClass. The childModel can bring in its own definitiion of properties and methods. Validation and property changed notification works fine with overrriden properties but wondering what is the best way if I implement a new property which has not been defined in MyBaseModel?

I have changed:

MyBaseModel<TModel>: ModelBase<MyBaseModel<TModel>> 


MyBaseModel: ModelBase<MyBaseModel>

As said earlier, this thread was and is meant to be just a discussion. Any other input is welcome.