// 出现未处理的异常时执行的代码 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { if (Debugger.IsAttached) { // 出现未处理的异常;强行进入调试器 Debugger.Break(); } //弹出错误信息 MessagePrompt errorPrompt = new MessagePrompt(); errorPrompt.ActionPopUpButtons.Clear(); Button okButton = new Button(); okButton.Content = "返回"; okButton.Click+=(s,args)=> { errorPrompt.OnCompleted(new PopUpEventArgs<string, PopUpResult>() { PopUpResult = PopUpResult.Cancelled }); }; errorPrompt.ActionPopUpButtons.Add(okButton); Button sendButton = new Button(); sendButton.Content = "发送错误信息"; sendButton.Click += (s, args) => { EmailComposeTask emailTask = new EmailComposeTask(); string errorMsg = ""; if (e.ExceptionObject != null) { errorMsg = "[Message]:" + e.ExceptionObject.Message + "\n\n\n[Source]:" + e.ExceptionObject.Source + "\n\n\n[StackTrace]:" + e.ExceptionObject.StackTrace; } emailTask.Body = errorMsg; emailTask.Subject = "WinDou应用错误报告"; emailTask.To = "*****@*****.**"; emailTask.Show(); }; errorPrompt.ActionPopUpButtons.Add(sendButton); errorPrompt.Message = "对不起,程序出错了,请重新尝试或重启应用"; errorPrompt.Show(); e.Handled = true; }
private void MessageSuperClick(object sender, RoutedEventArgs e) { var messagePrompt = new MessagePrompt { Title = "Advanced Message", Background = _naturalBlueSolidColorBrush, Foreground = _aliceBlueSolidColorBrush, Overlay = _cornFlowerBlueSolidColorBrush, }; var btnHide = new RoundButton { Content = "Hide" }; btnHide.Click += (o, args) => messagePrompt.Hide(); var btnComplete = new RoundButton { Content = "Complete" }; btnComplete.Click += (o, args) => messagePrompt.OnCompleted(new PopUpEventArgs<string, PopUpResult> { PopUpResult = PopUpResult.Ok, Result = "You clicked the Complete Button" }); messagePrompt.ActionPopUpButtons.Clear(); messagePrompt.ActionPopUpButtons.Add(btnHide); messagePrompt.ActionPopUpButtons.Add(btnComplete); messagePrompt.Completed += PopUpPromptStringCompleted; messagePrompt.Show(); }