<Window x:Class="DialogHost.ClosingConfirmation.CodeBehind.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<materialDesign:DialogHost> </materialDesign:DialogHost>
</Window>
    protected override async void OnClosing(CancelEventArgs e)
{
base.OnClosing(e); //If the user has elected to allow the close, simply let the closing event happen.
if (_AllowClose) return; //NB: Because we are making an async call we need to cancel the closing event
e.Cancel = true; //we are already showing the dialog, ignore
if (_ShowingDialog) return; TextBlock txt1 = new TextBlock();
txt1.HorizontalAlignment = HorizontalAlignment.Center;
txt1.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFF53B3B"));
txt1.Margin = new Thickness();
txt1.TextWrapping = TextWrapping.WrapWithOverflow;
txt1.FontSize = ;
txt1.Text = "您确认要退出系统吗?"; Button btn1 = new Button();
Style style = Application.Current.FindResource("MaterialDesignFlatButton") as Style;
btn1.Style = style;
btn1.Width = ;
btn1.Height = ;
btn1.Margin = new Thickness();
btn1.Command = MaterialDesignThemes.Wpf.DialogHost.CloseDialogCommand;
btn1.CommandParameter = true;
btn1.Content = "是"; Button btn2 = new Button();
Style style2 = Application.Current.FindResource("MaterialDesignFlatButton") as Style;
btn2.Style = style2;
btn2.Width = ;
btn2.Height = ;
btn2.Margin = new Thickness();
btn2.Command = MaterialDesignThemes.Wpf.DialogHost.CloseDialogCommand;
btn2.CommandParameter = false;
btn2.Content = "否"; DockPanel dck = new DockPanel();
dck.Children.Add(btn1);
dck.Children.Add(btn2); StackPanel stk = new StackPanel();
stk.Width = ;
stk.Children.Add(txt1);
stk.Children.Add(dck); //Set flag indicating that the dialog is being shown
_ShowingDialog = true;
object result = await MaterialDesignThemes.Wpf.DialogHost.Show(stk);
_ShowingDialog = false;
//The result returned will come form the button's CommandParameter.
//If the user clicked "Yes" set the _AllowClose flag, and re-trigger the window Close.
if (result is bool boolResult && boolResult)
{
_AllowClose = true;
Close();
}
}

源代码:https://github.com/Keboo/MaterialDesignInXaml.Examples/tree/master/DialogHost/DialogHost.ClosingConfirmation.CodeBehind

DialogHost 关闭对话框的更多相关文章

  1. 20151124001 关闭C#主窗体弹出是否关闭对话框

    关闭C#主窗体弹出是否关闭对话框 private void Frm_Main_FormClosing(object sender, FormClosingEventArgs e)        {   ...

  2. JQuery Dialog 禁用X按钮关闭对话框,-摘自网络

    JQuery Dialog 禁用X按钮关闭对话框,禁用ESC键关闭代码如下:$("#div1").dialog({   closeOnEscape: false,   open: ...

  3. 关闭C#主窗体弹出是否关闭对话框

    在开发系统时,常常有这样一个问题,就是当关闭主窗体,也即退出系统时,如果想提示是否关闭,以免误操作,可以在主窗体的Main_FormClosing事件中添加一个对话框,代码如下: private vo ...

  4. Android系统原理与源码分析(1):利用Java反射技术阻止通过按钮关闭对话框

    原文出处:博主宇宙的极客http://www.cnblogs.com/nokiaguy/archive/2010/07/27/1786482.html 众所周知,AlertDialog类用于显示对话框 ...

  5. mui 对话框 点击按钮不关闭对话框的办法

    目前版本的 mui.js 点击对话框的按钮只能关闭对话框 做如下修改 点击按钮后return false 即可

  6. Android——点击对话框上按钮不关闭对话框

    有时候我没可能需要在点击按钮进行一些检测,但是并不想关闭次对话框(系统默认点击任何一个按钮则关闭对话框),处理方法如下:在点击事件下添加如下代码: try { Field field = dialog ...

  7. vue + ElementUI 关闭对话框清空验证,清除form表单

    前面跟大家提到过 elementUI验证的问题,那么今天就来看看 点击对话框和关闭按钮 怎么清空验证,清空form表单,避免二次点击还会有 验证错误的提示 1.首先在你的对话框 取消按钮 加一个cli ...

  8. Android——点击对话框上button不关闭对话框

    有时候我没可能须要在点击button进行一些检測.可是并不想关闭次对话框(系统默认点击不论什么一个button则关闭对话框),处理方法例如以下:在点击事件下加入例如以下代码: try { Field  ...

  9. MFC对话框程序 屏蔽ESC和ENTER键关闭对话框的方法

    http://blog.csdn.net/xgx198831/article/details/6713651 MFC对话框程序  屏蔽ESC和ENTER键关闭对话框的方法 或许还有其它更好的办法,但下 ...

随机推荐

  1. Unity3D for iOS初级教程:Part 3/3(上)

    转自:http://www.cnblogs.com/alongu3d/archive/2013/06/01/3111738.html 欢迎来到第三部分,这是Unity 3D for iOS初级系列教程 ...

  2. 升级xcode10.0, 终端运行 运行报错:Print: Entry, “:CFBundleIdentifier”, Does Not Exist

    目录 问题原因 解决方法 终端解决 Print: Entry, ":CFBundleIdentifier", Does Not Exist 第一步: 去官网GitHub下载对应包就 ...

  3. [Python Modules] unittest.mock

    五夜光寒,照来积雪平于栈.西风何限,自起披衣看. 对此茫茫,不觉成长叹.何时旦,晓星欲散,飞起平沙雁. 在某个Python程序中看到这么一行 from unittest import mock 看起来 ...

  4. Python3 函数基础1

    目录 定义函数 定义函数的三种形式 空函数 有参函数 无参函数 函数的调用 函数的返回值 函数的参数 形参 (parameter) 实参(argument) 位置形参与位置实参 默认形参 关键字实参 ...

  5. Appium移动端自动化测试--控件定位方法

    常用定位手段 id Accessibility ID XPath 控件基础知识 DOM: Document Object Model文档对象模型 DOM应用:最早应用于HTML和Javascript的 ...

  6. C# 使用自带Microsoft.Office.Interop.Excel简单操作Excel文件

    项目添加应用 Microsoft.Office.Interop.Excel.dll 文件 引用命名空间: using Excel = Microsoft.Office.Interop.Excel; 简 ...

  7. maven 利用 profile 进行多环境配置

    我们在进行项目的多环境配置时,有很多种方式供我们选择,比如 SpringBoot 自带的 application-dev.yml.maven 的 profile 等.这里介绍的就是如何利用 profi ...

  8. python:json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes问题解决

    有如下一个文件,内容如下 { "test1": "/root/test/test1.template", "test2": "/r ...

  9. [ASP.NET Core 3框架揭秘] 文件系统[4]:程序集内嵌文件系统

    一个物理文件可以直接作为资源内嵌到编译生成的程序集中.借助于EmbeddedFileProvider,我们可以采用统一的编程方式来读取内嵌的资源文件,该类型定义在 "Microsoft.Ex ...

  10. sqlserver数据库批量插入-SqlBulkCopy

    当想在数据库中插入大量数据时,使用insert 不仅效率低,而且会导致一系列的数据库性能问题 当使用insert语句进行插入数据时.我使用了两种方式: 每次插入数据时,都只插入一条数据库,这个会导致每 ...