SavableModelBase, Load from XML, OnPropertyChanged

Topics: Questions
Jan 14, 2013 at 5:56 PM


I am using SavableModelBase<MyClass> to serialize/deserialize to/from XML.

This is very useful and works very well - so first thing off - big THANKS.

Now, I have a property that when it changes I want other properties to change with it. I want it to happen also when I am loading the class from an XML file.

I tired several ways:

  • Add the update code inside the property setter but when I load from XML I don't see it being called
  • Overriding "OnPropertyChanged" but for some reason this only fires for some properties
  • Added a changed event handler in the PropertyData constructor (using datapropchanged template) but this doesn't fire as well.

I assume I am missing something in how the Load function works - maybe it sets some properties directly?

Any hints will be appreciated.


Jan 14, 2013 at 6:00 PM

Just make sure that you register your own OnPropertyChanged (using the datapropchanged). In the changed handler, call RaisePropertyChanged for the other properties.

Note that changes are only detected for Catel properties, not for your own. You might consider Catel.Fody. See the docs for more info. The thing is that it can automatically convert an auto property into a catel property. If you write "private void On[PropertyName]Changed()", it will automatically subscribe to events for you.