MVVM 路由和中继命令 [英] MVVM Routed and Relay Command

查看:20
本文介绍了MVVM 路由和中继命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RoutedCommandRelayCommand ?什么时候使用 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 路由和中继命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆