Detect Parent change

Detect Parent change

Old forum URL: forums.lhotka.net/forums/t/8339.aspx


nelis posted on Wednesday, January 13, 2010

Suppose a child object would like to add/remove an event handler to it's Parent property. It needs to know when the Parent is set. However SetParent ain't virtual. I can't seem to find the proper place to do this. Any ideas?

RockfordLhotka replied on Wednesday, January 13, 2010

Interesting - no one has ever asked for this capability.

Good framework design dictates that things are only made visible, virtual or otherwise extensible when there's a valid reason to do so. Since this has never come up, you can see why it isn't possible :)

I'll add it to the wish list. In CSLA 4 the Parent properties are becoming public, and this seems like a reasonable change to go along with that change.

nelis replied on Thursday, January 14, 2010

Thanks, an alternative would be calling OnPropertyChanging and OnPropertyChanged from SetParent

RockfordLhotka replied on Thursday, January 14, 2010

Maybe PropertyChanged would work. Maybe PropertyChanged would break data binding.

Raising that event for parent-child interactions has proven to be problematic in the past - though those cases were ones where the parent raised the event due to something the child did. Maybe it would be OK for the child to raise the event based on something the parent did. Extensive testing would be required across all smart client UI models.

Making the method virtual seems a lot simpler :)

nelis replied on Friday, January 15, 2010

It is only recently that I understood that PropertyChanged is mainly meant to inform UIs to update. Not so much to detect actual changes in property values (or am I wrong ?)

rsbaker0 replied on Friday, January 15, 2010

nelis:
It is only recently that I understood that PropertyChanged is mainly meant to inform UIs to update. Not so much to detect actual changes in property values (or am I wrong ?)


Well, this is also the method by which property changes cause an object to be dirty, and hence savable...

am_fusion replied on Tuesday, February 23, 2010

Hey Rocky,

 

We just found ourselves in the same spot... we want to be able to detect when the parent has changed.  My understanding, from reading this thread, is that there is now a wish list item for v4.0 to make SetParent virtual.

 

We are in a situation such that we will not be able to upgrade to v4.0 ('soon'?) so I was thinking about making this change to our CSLA 3.8.2 code base (taking the hit to make this change every time we upgrade 3.8.x)...  do you think this is a 'safe' change to make?

RockfordLhotka replied on Tuesday, February 23, 2010

I think that change is already in CSLA 4, so you can copy the implementation from svn if you'd like.

am_fusion replied on Tuesday, February 23, 2010

Sweet!!! thnx.

am_fusion replied on Tuesday, February 23, 2010

FYI, It looks like the changes were made to the core lib, but not the silverlight lib.

Copyright (c) Marimer LLC