wpf metro 点右上角关闭询问是否关闭

MainWindow.xaml中,添加Closing="MetroWindow_Closing"

在窗体的属性为Closing事件绑定方法

MainWindow.xaml.cs中

      using System.Threading;


     #region 窗体关闭 /// <summary> /// 窗体关闭 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { e.Cancel = true; CancellationToken token; TaskScheduler uiSched = TaskScheduler.FromCurrentSynchronizationContext(); Task.Factory.StartNew(DialogsBeforeExit, token, TaskCreationOptions.None, uiSched); }


/// <summary> /// 关闭窗体之前的提示对话框 /// </summary> private async void DialogsBeforeExit() { MessageDialogResult result = await this.ShowMessageAsync(this.Title, "您真的要离开吗?", MessageDialogStyle.AffirmativeAndNegative); if (result == MessageDialogResult.Negative) { return; } else//确认退出 {
System.Environment.Exit(System.Environment.ExitCode);
//关闭程序 } } #endregion

猜你喜欢

转载自www.cnblogs.com/longzhankunlun/p/9509657.html
今日推荐