当前位置:网站首页>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);
}
}
边栏推荐
- [MySQL 13] if you change your password for the first time after installing mysql, you can skip MySQL password verification to log in
- Technical dry goods Shengsi mindspire dynamic transformer with variable sequence length has been released!
- Screenshot tool snipaste
- Go language foundation ----- 01 ----- go language features
- haproxy+keepalived搭建01
- What to do after the browser enters the URL
- Go language foundation ----- 18 ----- collaboration security, mutex lock, read-write lock, anonymous lock, sync Once
- Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico
- 研究显示乳腺癌细胞更容易在患者睡觉时进入血液
- Introduction of novel RNA based cancer therapies
猜你喜欢
Go language foundation ----- 04 ----- closure, array slice, map, package
An article for you to understand - Manchester code
Go language foundation ----- 08 ----- interface
Go language foundation ------ 14 ------ gotest
Screenshot tool snipaste
Robots protocol
The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.
【踩坑系列】mysql 修改root密码失败
Iterm2 setting
Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework
随机推荐
Redis配置文件
Microsoft Security Response Center
What is a data type? What is the use of data types?
WorldView卫星遥感影像数据/米级分辨率遥感影像
【MySQL 14】使用DBeaver工具远程备份及恢复MySQL数据库(Linux 环境)
PAT甲级 1029 Median
regular expression
JS to implement publish and subscribe
idea取消引用顯示效果
微软安全响应中心
Technical dry goods | some thoughts on the future of AI architecture
华为交换机:配置telnet和ssh、web访问
Differences between tp3.2 and tp5.0
go语言-循环语句
EtherCAT state machine transition (ESM)
PostGIS space function
Robots protocol
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework
Technical dry goods | alphafold/ rosettafold open source reproduction (2) - alphafold process analysis and training Construction