2010-02-12 147 views

回答

13

您可以使用DispatcherUnhandledException

XAML(App.xaml中):

<Application x:Class="App.App" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    StartupUri="wndMain.xaml" DispatcherUnhandledException="Application_DispatcherUnhandledException"> 

代碼隱藏(App.xaml.cs/VB:

private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) 
{ 
    // Handle error here 

    ... 

    // Prevent default unhandled exception processing by WPF 
    e.Handled = true; 
} 

閱讀起來more here始終儘管做了正確數量的錯誤處理,但不要讓錯誤進入這種方法。