I want to find out the event handling scheme using the MVVM pattern.
- As I understand it, there should be no event handler in the code, since they are possible only in the code behind, and it is bad to use it, right?
All event processing takes place through commands. To do this, you need to write a simple class like this, in which to insert your delegates, create command properties and bind them to elements?
class RelayCommand : ICommand { private Action<object> _executeDelegate; public RelayCommand(Action<object> executeDelegate) { _executeDelegate = executeDelegate; } public bool CanExecute(object parameter) { return true; } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { _executeDelegate(parameter); } }And how to handle different events from the same element? As I understand it, the command is executed for a single "main" event?
- Is it possible to get event arguments (the same arguments as a regular handler)?
- Are there any more beautiful methods? For example, through command binding? Just how do these bindings add to the window if the ViewModel does not have a link to it?