Event ObjectChanged ?
Old forum URL: forums.lhotka.net/forums/t/1135.aspx
JoOfMetL posted on Wednesday, September 06, 2006
Hello,
I would like that my objects have a new event: ObjectChanged.
This event will be launched when any property of my object, or one of
its children, or one of its grandChild are modified.
There is the event propertyChanged, but he is launched when one of the
properties is modified (what normal), but not if a child is
modified.
My problem arises when my object has grandchild, and I don't know how
to go up information to announce that a grandchild is modified.
Have an idea?
Thank you
Brian Criswell replied on Wednesday, September 06, 2006
Just attach an event handler to each of your child changed events (ListChanged, PropertyChanged, etc.) and call OnPropertyChanged(string.Empty).
JoOfMetL replied on Wednesday, September 06, 2006
I wanted to use the OnPropertyChanged event, but I don't want reload all my objet.
If a property of a grandChild is modified, I do not want that the data
of my EditableRoot is reloaded. For a single object, it is not
inevitably annoying, but for a collection, that creates a problem. So I
wanted to avoid using the OnPropertyChanged event
What do you think about it?
Brian Criswell replied on Wednesday, September 06, 2006
My personal opinion is that it is better to work within the .NET framework when possible and practical. Using PropertyChanged will make changes work with data binding which will be useful if you ever have a root object rule property that recalculates based on changes in its children.
What problem are you experiencing with collections?
JoOfMetL replied on Wednesday, September 06, 2006
I was afraid that if a collection were displayed with each time a
property of a grandChild was modified, the screen is continuously
updated is thus worse performances.
I will test like that to see the result.
DansDreams replied on Wednesday, September 06, 2006
The only time this seems to be a problem is with list controls displaying large collection. But in that case the list control is going to be responding to the collection's change events anyway. There are cases where you need to turn off that event/handler cycle when doing lots of updates to a displayed collection in code, but the effect on the controls displaying the parent object is usually fairly trivial.JoOfMetL replied on Thursday, September 07, 2006
I implement the solution :
Attach an event handler to each of child changed events
(ListChanged, PropertyChanged, etc.) and call
OnPropertyChanged(string.Empty).
And it's works.
Thank you
Copyright (c) Marimer LLC