开发者

Raising RoutedEvents in non-UIElement class

开发者 https://www.devze.com 2023-01-16 06:01 出处:网络
It seems that the entire power of routedevents is directed towards UI development. Meaning to ask, would it be possible to raise a routed event from a class that does not extend a UIElement or UserCon

It seems that the entire power of routedevents is directed towards UI development. Meaning to ask, would it be possible to raise a routed event from a class that does not extend a UIElement or UserControl class at all? For example: I create a State class that I that performs several changes on some data (mainly drawings and objects) and I want the to inform the main UI so that it can update its Adorners and cause a repaint of the visual element.

I think it's good to also somewhat decouple this State cl开发者_运维百科ass from the UI instead of creating an event handler that the main UI should directly attach to if it wants to service this event.

Is there a way to achieve this or am I completely off?


You should look up the ICommand interface and implement it in a custom command class.

Alternatively, you could look up the RelayCommand implementation that allows for the definition of a command without the need for implementing a class.

For the difference between the RoutedCommand and the RelayCommand you can read this discussion.

0

精彩评论

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