I have a WPF Application that I have been trying to write in the MVVM style. If an Exception is thrown (like when a document is opened), I would like to display a MessageBox.
Use a service:
public void SomeMethodInYourViewModel()
{
try
{
DoSomethingDangerous();
}
catch (Exception ex)
{
ServiceLocator.Resolve().ShowMessage(ex.Message);
}
}
You have now decoupled your VMs from the presentation of messages. You may even decide not to use the standard (ugly) message boxes at all and that won't affect your VMs.