简体   繁体   中英

WPF Routed Events and Command in MVVM

After reading Routed Events and Commands, a question comes in my mind when we write code using MVVM

Routed Events is used in dependency property and Routed Commands is used in View Model.

Is my understanding correct?

There are many ways to use routed events and routed commands but in the context of a typical MVVM pattern, routed events and routed commands are both part of the view, not the view-model. The reason is that the routing is inherently view-specific: bubbling and tunneling are controlled by and applicable to the visual tree which is part of the view. Once the routed event or routed command has found a target and that target has a data-context, then typically you can dispatch the routed event or routed command to a non-routed command in the view-model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM