In a WPF application (C#) I’ve got an instance of ObjectX in a class ClassA. This ClassA is instantiated in ClassB.
Hence ClassB -> contains instance of -> ClassA -> which contains an instance of -> ObjectX
ObjectX raises an EventA. I need to handle this event in ClassB.
What is this concept called (Event Delegation, Event Routing, …)? And how can it be done?
In WPF it is called Routed events, but this will work only if both of these are true:
LogicalTreeHelperstates that your controls are parents/children to each other.tunelledorbubblingwill work. If it is not then routing events won’t help you.I have a feeling that all you need is something like this:
in class B:
but this has nothing to do with WPF.
UPD: or something like this if you don’t want to make instanceOfX accessible:
classAand raise it wheneverinstanceOfXraises its eventClassBhandleinstanceOfA.MyEventIn this case you may keep
instanceOfXprivate but you’ll have to add one more event in the middle.