I was just googling the difference between WPF Command and Event in WPF. i landed on the following page of stackoverflow where the discussion is going on.
What is the difference between WPF Command and Event?
I am only able to understand following from there
- Commands can be written in business layer while event only in presentation
- A single command can be associated with many controls but event can only be associated with only one control.
Am I right? Is there any other difference between them?
You're right but only partly.
MVVM
paradigm. Simply saying events are hardly pluggable, you can't bind to event handler. Nevertheless there is no limit to use commands in presentation layer but there is no benefits of doing so. As well as you could catch your control in BLL and attach event handler to it but this case is even worse.Also commands gives you some free benefits. For example using command element'll be disabled if
CanExecute()
returns false. Another benefit is that using commands forces you to fo follow Separation of concerns principle.An Event is a trigger that occurs when something happens in the UI. A Command is how this event is handled by your domain model.