简体   繁体   English

MvvmCross Wpf异常处理

[英]MvvmCross Wpf Exception Handling

I am new to Wpf using MvvmCross. 我是使用MvvmCross的Wpf新手。 I have been using MvvmCross for WindowsPhone App for a while now and exception handling isn't that hard because I can use the default App.xaml.cs and its UnhandledException event. 我已经将MvvmCross用于Windows Phone App已有一段时间了,并且异常处理并不难,因为我可以使用默认的App.xaml.cs及其UnhandledException事件。 However, in a WPF project, the App.xaml.cs file is empty so whenever one of my ViewModels encounters an exception, it crashes because I don't know where to handle exceptions. 但是,在WPF项目中,App.xaml.cs文件为空,因此每当我的ViewModel之一遇到异常时,它都会崩溃,因为我不知道在哪里处理异常。

How can I fix this? 我怎样才能解决这个问题?

You should be able to use UnhandledException in a similar manner to your Windows Phone App. 您应该能够以与Windows Phone应用类似的方式使用UnhandledException。

As explained by Stuart for WPF here , under "Modify the App.xaml.cs to Use Setup", you should have a DoSetup method in App.xaml.cs. 如Stuart for WPF 此处所述 ,在“修改App.xaml.cs以使用安装程序”下,您应该在App.xaml.cs中具有DoSetup方法。

You can then add event handlers something like this: 然后,您可以添加事件处理程序,如下所示:

DispatcherUnhandledException += OnDispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM