<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. luogu P3572 [POI2014]PTA-Little Bird

    题目描述 从1开始,跳到比当前矮的不消耗体力,否则消耗一点体力,每次询问有一个步伐限制,求每次最少耗费多少体力 单调队列优化动态规划 #include<cstdio> #include&l ...

  2. TortoiseGit 设置ssh方式

    TortoiseGit使用扩展名为ppk的密钥,而不是ssh-keygen生成的rsa密钥. 也就是说使用 ssh-keygen  -t rsa  -C "576953565@qq.com& ...

  3. 使用 Spring 提供的 restTemplate 完成 Http 服务消费

    RestTemplate 介绍 RestTemplate 是 Spring 提供的用于访问 Rest 服务的客户端,RestTemplate 提供了多种便捷访问远程 Http 服务的方法,能够大大提高 ...

  4. [Java并发] AQS抽象队列同步器源码解析--锁获取过程

    要深入了解java并发知识,AbstractQueuedSynchronizer(AQS)是必须要拿出来深入学习的,AQS可以说是贯穿了整个JUC并发包,例如ReentrantLock,CountDo ...

  5. Asp.net Core 异常日志与API返回值处理

    需求: 1.对异常进行捕获记录日志 并且修改返回值给前端 解释: ILogger4是自定义的一个日志,更改它就好 解决方案1: 使用中间件进行异常捕获并且修改其返回值 public class Err ...

  6. 工具类中注入service和dao

    今天编写了个工具类需要用到service成和dao层的代码 如下: //第一步:需要将工具类注入到容器中 @Component public class RuleUtils { ​ //第二部注入 @ ...

  7. 【hibernate】自定义转换器

    [hibernate]自定义转换器 转载:https://www.cnblogs.com/yangchongxing/p/10398255.html 1.转换基本属性 package cn.ycx.s ...

  8. 《CSAPP》实验一:位操作

    <CSAPP>号称程序员圣经,虽然中文译名为<深入理解计算机系统>,但其实没那么"深",只是覆盖面很广,一般用作计算机专业大一导论课的教科书.早就听闻书上配 ...

  9. JS---封装getScroll函数 & 案例:固定导航栏

    封装getScroll函数 1. 获取页面向上或者向左卷曲出去的距离的值 2. 浏览器的滚动事件 function getScroll() { return { left: window.pageXO ...

  10. GeoServer 2.15.0版本跨域问题解决方法

    geoserver默认不开启跨域设置,开启步骤如下: 1.修改配置文件web.xml,该配置文件的路径如下 \webapps\geoserver\WEB-INF\web.xml 2.搜索:cross- ...