问题描述
RoutedCommand 和 RelayCommand ?什么时候使用 RoutedCommand 什么时候使用 RelayCommand 在 MVVM 模式中?
What is the Difference between the RoutedCommand and RelayCommand ? When to use RoutedCommand and when to use RelayCommand in MVVM pattern ?
推荐答案
RoutedCommand 是 WPF 的一部分,而 RelayCommand 是由 WPF 门徒 Josh Smith 创建的;)
RoutedCommand is part of WPF, while RelayCommand was created by a WPF Disciple, Josh Smith ;).
说真的,RS Conley 描述了一些差异.关键区别在于 RoutedCommand 是一个 ICommand 实现,它使用 RoutedEvent 路由通过树,直到找到命令的 CommandBinding,而 RelayCommand 不进行路由,而是直接执行某个委托.在 M-V-VM 场景中,RelayCommand(Prism 中的 DelegateCommand)可能是更好的选择.
Seriously, though, RS Conley described some of the differences. The key difference is that RoutedCommand is an ICommand implementation that uses a RoutedEvent to route through the tree until a CommandBinding for the command is found, while RelayCommand does no routing and instead directly executes some delegate. In a M-V-VM scenario a RelayCommand (DelegateCommand in Prism) is probably the better choice all around.
这篇关于MVVM 路由和中继命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!