开发者

C#/WPF - RoutedEvent in WPF class that isn't a UIElement

开发者 https://www.devze.com 2022-12-24 06:17 出处:网络
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 d

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 RoutedEvents. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号