Reputation: 5003
My WPF application shows a tree of objects having some properties. These properties can be modified from the UI via data bindings. Objects themselves can be added or deleted. Nothing special.
The question is: What's the best way to be aware of changes somewhere in the objects tree?
Ideas considered so far:
INotifyPropertyChanged
on every object and let them all notify their parents about modifications so I can listen to one event on the objects tree rootTextChanged
, Checked
etc.They all look like ugly mesh, so I'm afraid to implement anything of them.
Upvotes: 1
Views: 332
Reputation: 5003
In case, comeone will be ever interested, I ended up subclassing all my objects in the tree from the common ancestor responsible for tracking IsDirty
state and promoting it up and down the tree of objects. I mean that if some object is marked as dirty then all it's parents are considered dirty too. And yes, I implemented INotifyPropertyChanged
in this common superclass to be aware of the changes.
Upvotes: 0
Reputation: 61599
INotifyPropertyChanged is probably the best way to go, as it would allow you to bubble up change notifications from any root node. I guess it would also depend how complex your types are, and what sort of changes you want to react to?
Upvotes: 2