Search code examples
c#mvvmicommand

What is the difference between ActionCommand and DelegateCommand


I would appreciate if someone could tell me what are the differences and benefits in using ActionCommand class from the Expression Blend and DelegateCommand class (Prism)?

If I understand correctly the DelegateCommand supports two delegates while the ActionCommand class supports only a single Execute delegate. Any other differences? After reading the documentation and online I still can't quite understand what are the benefits of using either one.

Thanks in advance


Solution

  • The DelegateCommand allows delegating the commanding logic instead of requiring a handler in the code behind. It uses a delegate as the method of invoking a target handling method. Like

    public class DelegateCommand<T> : ICommand
    {
        public DelegateCommand(Action<T> executeMethod, Func<T, bool> canExecuteMethod)
        {
            …
            this.executeMethod = executeMethod;
            this.canExecuteMethod = canExecuteMethod;
            …
        }
    …
    }