C#/WPF - RoutedEvent in WPF class that isn't a UIElement
I have a class that needs to notify that something significant has occurred. The class is in a WPF-project, even though this specific class, is lookless (and doesn't inherit from UIElement
, neither directly or indirectly).
Normally, I just register a RoutedEvent
to get this functionality but as this class neither has 开发者_如何学JAVAAddHandler nor RemoveHandler, I can't get it to work. Anyone knows of another way of get the RoutedEvent
behaviour?
As far as I know, if your class isn't a UIElement
, it cannot be part of the visual tree, and if it isn't part of the visual tree, you cannot throw RoutedEvent
s. They're strictly a UI concept.
I think the recommended approach would be to either make your class inherit from UIElement
, or if that's not possible/desired, create a counterpart for your class which does inherit from UIElement
and use this second class in the visual tree where you would normally place your original class.
精彩评论