当前位置:网站首页>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);
}
}
边栏推荐
- Professor Zhang Yang of the University of Michigan is employed as a visiting professor of Shanghai Jiaotong University, China (picture)
- Go language foundation ----- 09 ----- exception handling (error, panic, recover)
- C2 several methods of merging VCF files
- 创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
- Redis profile
- 华为交换机配置ssh登录远程管理交换机
- 【cocos creator】点击按钮切换界面
- HDMI2.1与HDMI2.0的区别以及转换PD信号。
- 一个实习生的CnosDB之旅
- Microsoft Security Response Center
猜你喜欢

什么是数据类型?数据类型有什么用?

Analysis of the problems of the 12th Blue Bridge Cup single chip microcomputer provincial competition

Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)

Iterm2 setting

在浏览器输入url后执行什么

Redis batch startup and shutdown script

Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework
![[MySQL 12] MySQL 8.0.18 reinitialization](/img/e1/9874df18bbc8d80c3c5c5fe39aefc9.png)
[MySQL 12] MySQL 8.0.18 reinitialization
![[step on the pit series] MySQL failed to modify the root password](/img/d0/f975baf18bac506208abff3713ac03.png)
[step on the pit series] MySQL failed to modify the root password

Go language foundation ----- 06 ----- anonymous fields, fields with the same name
随机推荐
PAT甲级 1028 List Sorting
What is a data type? What is the use of data types?
GoLang之结构体
VMware virtual machine configuration static IP
【LeetCode】2. Valid parentheses · valid parentheses
Technical dry goods | alphafold/ rosettafold open source reproduction (2) - alphafold process analysis and training Construction
Structure of golang
Technical dry goods Shengsi mindspire dynamic transformer with variable sequence length has been released!
【MySQL 14】使用DBeaver工具远程备份及恢复MySQL数据库(Linux 环境)
An intern's journey to cnosdb
Research shows that breast cancer cells are more likely to enter the blood when patients sleep
Go language foundation ----- 10 ----- string related operations (operation function, string conversion)
Screenshot tool snipaste
yarn link 是如何帮助开发者对 NPM 包进行 debug 的?
PHP common sorting algorithm
UA camouflage, get and post in requests carry parameters to obtain JSON format content
Technical dry goods | hundred lines of code to write Bert, Shengsi mindspire ability reward
Go language foundation ----- 15 ----- reflection
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)
register关键字