views:

27

answers:

1

Hi,

I am having a number of controls in my application(which user can add to canvas), each having various properties(mostly dependency properties). User can change its properties through property grid(like color, text etc.).

I have save functionality implemented, so if user makes any change in canvas we ask him to save the document before leaving. At present I am keeping track of Add/Delete/Resize like operations(changing IsChanged flag to true). I also want to keep track of any property changes done by user, say if he changes the color of control through propertygrid.

One straightforward solution is to handle PropertyChangedCallback for each proeprty and set the flag in that. Problem with this is that I will have to write PropertyChangedCallback for each proeprty in each control, and at the same time I will have to make sure that every new proeprty added do the same.

My question: Is there any other better way of tracking property changes, say at some global place?

+1  A: 

If your objects/classes are DependencyObjects, you could create your own 'base class', deriving from DependencyObject which overrides OnPropertyChanged:

http://msdn.microsoft.com/en-us/library/system.windows.dependencyobject.onpropertychanged.aspx

In the implementation you could register that the object had changed in some singleton or associated change-tracking manager class, then call base.OnPropertyChanged.

Then change all your objects to implement this new class rather than DependencyObject and when any properties change your code will get called.

Hope that helps!

Kieren Johnstone
Exactly what I was looking for :) I already have a base class for my controls which derive from UserControl so implementing this was easyyy :)
akjoshi