当前位置:网站首页>WPF:解决MaterialDesign:DialogHost 无法关闭问题
WPF:解决MaterialDesign:DialogHost 无法关闭问题
2022-07-03 07:53:00 【彼岸大洋】
使用MaterialDesion 开发WPF应用程序:做有遮罩的弹窗效果:
DialogHost.Show
如上图所示:点击“确定”按钮可关闭弹窗;
关闭按钮的绑定命令如下:
<Button IsDefault="True" Style="{StaticResource MaterialDesignFlatButton}"
Width="160" Height="40" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Content="确定"></Button>
如果希望后台能关闭弹窗:
使用下面的写法可能不会生效:
DialogHost.CloseDialogCommand.Execute(null, null);
换了个思路解决了问题:
var session = DialogHost.GetDialogSession(ROOT_DIALOG_ID);
if (session == null)
{
return;
}
session.Close();
同理:如果弹窗过程中需要更新弹窗的显示内容,可以使用session.Update();
例如:
/// <summary>
/// 弹窗提示,用户自行关闭
/// </summary>
/// <param name="text"></param>
public static void PopHint(string text)
{
var dialog = new PopMessageBoxe
{
Message = { Text = text }
};
var session = DialogHost.GetDialogSession(ROOT_DIALOG_ID);
if (session == null)
{
DialogHost.Show(dialog, ROOT_DIALOG_ID, ExtendedOpenedEventHandler);
}
else
{
session.UpdateContent(dialog);
}
}
边栏推荐
- Go language foundation ----- 04 ----- closure, array slice, map, package
- Pat grade a 1029 median
- idea取消引用顯示效果
- Pat class a 1028 list sorting
- *p++、*++p、++*p、(*p)++
- How does yarn link help developers debug NPM packages?
- Project experience sharing: handwritten Chinese character recognition based on Shengsi mindspire
- Redis batch startup and shutdown script
- 【MySQL 13】安装MySQL后第一次修改密码,可以可跳过MySQL密码验证进行登录
- C2-关于VCF文件合并的几种方法
猜你喜欢
Harmonyos third training notes
haproxy+keepalived搭建01
UA camouflage, get and post in requests carry parameters to obtain JSON format content
【LeetCode】2. Valid Parentheses·有效的括号
Go language foundation ----- 09 ----- exception handling (error, panic, recover)
Redis批量启停脚本
Go language foundation ------ 14 ------ gotest
Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation
Getting started with minicom
Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task
随机推荐
idea取消引用显示效果
go语言-循环语句
C language learning notes (mind map)
Project experience sharing: handwritten Chinese character recognition based on Shengsi mindspire
微软安全响应中心
Go language foundation ----- 09 ----- exception handling (error, panic, recover)
PAT甲级 1029 Median
Differences between tp3.2 and tp5.0
[at] abc 258G - Triangle 三元组可达-暴力
密西根大学张阳教授受聘中国上海交通大学客座教授(图)
Go language foundation ----- 10 ----- string related operations (operation function, string conversion)
Redis批量启停脚本
VMware virtual machine configuration static IP
*p++、*++p、++*p、(*p)++
[at] abc 258G - Triangle 三元組可達-暴力
s7700设备如何清除console密码
Robots protocol
[untitled]
Pat class a 1032 sharing
Huawei switch: configure Telnet, SSH and web access