MVVM Exception Handling

后端 未结 3 1156
我寻月下人不归
我寻月下人不归 2021-02-04 14:22

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.

3条回答
  •  温柔的废话
    2021-02-04 15:13

    Have a look at Josh Smith's excellent MVVM Foundation on Codeplex. Specifically, have a look at the Messenger class, a lightweight way of passing messages between various ViewModel objects who do not need to be aware of each other.

    Also, I don't believe there is a hard-and-fast rule on "No code in the View", although it's best to be avoided if possible... remember that your XAML is simply .net code written in a declarative syntax; the code-behind is just C# or VB.net to supplement that (if absolutely necessary!)

提交回复
热议问题