Reputation: 1584
What is the Difference between the Delegate Command and Routed Command?
I read some article that says use Delegate Command on MVVM instead of Routed Command.
So What are the advantages of Delegate Command over Routed Command when we use MVVM?
Upvotes: 10
Views: 5330
Reputation: 884
Some advantages of using a DelegateCommand (a.k.a. RelayCommand) are:
1) Requires less XAML/code to support them (don't need CommandBindings)
2) Command implementation code can easily be written in ViewModel classes
3) They do not take a dependency on the UI element tree to work properly, which also helps improve performance
Since a lot of third-party UI controls use routed commands, most developers end up using routed commands when taking a dependency on those controls.
If you end up needing to use routed commands, check out my Using RoutedCommands with a ViewModel in WPF article to see a way to simplify things.
Upvotes: 11
Reputation: 184516
RoutedCommands are as the name says, routed, that means they travel the VisualTree either up or down and check if there are CommandBindings
for them. See the Routed Events Overview and Commanding Overview.
Also see the references for the respective classes:
DelegateCommand<T>
RoutedCommand
Upvotes: 3