在DispatcherUnhandledException上的App.xaml.cs中重置游标

时间:2013-09-24 10:13:24

标签: c# wpf

当发生DispatcherUnhandledException事件时,是否有可能(如果可以的话)在App.xaml.cs中重置光标。

在发生意外情况后进行清理。

1 个答案:

答案 0 :(得分:1)

假设您的意思是鼠标光标并且您想阻止应用程序崩溃:

<强>的App.xaml

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

<强> App.xaml.cs

private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
  // resets the cursor
  Mouse.OverrideCursor = null;

  // prevents the app from crashing
  e.Handled = true;
}