How can I listen to a RoutedEvent from a class that doesn't derive from FrameworkElement ? Can it be done?
-
09-06-2019 - |
Question
The question says it all basically.
I want in a
class MyClass
to listen to a routed event. Can it be done ?
Solution
Actually I wiredup the event the wrong way :|
I had
EventManager.RegisterClassHandler ( typeof ( MyClass )......
Instead of
EventManager.RegisterClassHandler ( typeof ( TheClassThatOwnedTheEvent )
So .. my bad.
OTHER TIPS
If you can create an inner class of MyClass (call it MyInnerClass) that derives from FrameworkElement while retaining the capability to access an enclosing MyClass object, your problem will be solved. You can then implement a 'getListener' method within MyClass that returns the embedded MyInnerClass that you will use to actually listen to events.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow