MVVM does not mean that you cannot use Code-Behind.
MVVM means your application logic should not be tied to user interface elements.
You can handle events in the code behind (for example, Window.Closing ) and send messages or execute methods in the ViewModel to react to this.
Here you do not violate MVVM by placing the event handler in the code behind. You break MVVM if you put logic that determines if the application can close in code. This is the responsibility of the application logic, and the application logic lives in ViewModels, not in views.
Federico berasategui
source share