Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delegate Command and Routed Command

Tags:

mvvm

wpf

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?

like image 700
pchajer Avatar asked Apr 19 '11 01:04

pchajer


1 Answers

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.

like image 192
Josh Smith Avatar answered Nov 16 '22 04:11

Josh Smith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!