问题描述
?
何时使用RoutedCommand和何时在MVVM模式中使用RelayCommand?
What is the Difference between the RoutedCommand and RelayCommand ? When to use RoutedCommand and when to use RelayCommand in MVVM pattern ?
推荐答案
是WPF的一部分,而由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路由和中继命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!