What is the best practice for handling exceptions when using command binding in WPF?

前端 未结 2 1702
粉色の甜心
粉色の甜心 2021-02-09 02:02

I am using the MVVM pattern for a WPF application. In several places I bind commands to input elements in the views as in the following XAML:

2条回答
  •  失恋的感觉
    2021-02-09 03:05

    I hate this answer, but it really depends on a context.

    Today I may use IoC, to get ILoggerService or INotificationSerivce or both and do the stuff when something went wrong. Tomorrow I may be happy with raw MessageBox.Show() somewhere in the DispatcherUnhandledException event handler. Or maybe I will write my own attached property ala

    and live with it...

    Probably the answer may go like this: "Choose the best method to communicate between two classes and use it". Sorry for being non concrete... Maybe somebody else will be more specific.

    NB: Interfaces' names, provided in the answer are not WPF standard. I use them just as an example.

    Cheers

提交回复
热议问题