Handling Dialogs in WPF with MVVM
- by Ray Booysen
In the MVVM pattern for WPF, handling dialogs is one of the more complex operations. As your view model does not know anything about the view, dialog communication can be interesting. I can expose an ICommand that when the view invokes it, a dialog can appear.
Does anyone know of a good way to handle results from dialogs? I am speaking about windows dialogs such as MessageBox.
One of the ways we did this was have an event on the viewmodel that the view would subscribe to when a dialog was required.
public event EventHandler<MyDeleteArgs> RequiresDeleteDialog;
This is OK, but it means that the view requires code which is something I would like to stay away from.