Search code examples
wpfmvvmcommandicommand

What are WPF commands for if we almost always use DelegateCommands?


Why WPF commands exists if almost on every situation a DelegateCommand is used, which its only function is to execute a method from the ViewModel instead of WPF directly supporting binding to methods?


Solution

  • There are existing, already implemented, WPF commands which perform certain tasks and there are custom commands which you can implement using the ICommand interface, to execute your specific tasks.

    Obviously Microsoft created a base set of commands only for tasks that are commonly used by everyone and providing the interface so you can create your own commands.

    I notice many developers don't know of the existing commands available and implement their own, basically performing the same functions (copy/paste/etc for example).

    From the existing command sets there are ApplicationCommands, NavigationCommands, MediaCommands, EditingCommands, ComponentCommands, etc.

    Here you can find an extensive explanation about the 'Commanding' system:

    https://msdn.microsoft.com/en-us/library/ms752308(v=vs.110).aspx