MVVM Routed and Relay Command

user72799 picture user72799 · Mar 16, 2009 · Viewed 51.9k times · Source

What is the Difference between the RoutedCommand and RelayCommand ? When to use RoutedCommand and when to use RelayCommand in MVVM pattern ?

Answer

wekempf picture wekempf · Mar 19, 2009

RoutedCommand is part of WPF, while RelayCommand was created by a WPF Disciple, Josh Smith ;).

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.