当前位置:网站首页>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);
}
}
边栏推荐
猜你喜欢

JS common basic case sorting (continuous update)

【cocos creator】点击按钮切换界面

Go language foundation ----- 06 ----- anonymous fields, fields with the same name

Technical dry goods | hundred lines of code to write Bert, Shengsi mindspire ability reward

【LeetCode】3. Merge two sorted lists · merge two ordered linked lists

WorldView卫星遥感影像数据/米级分辨率遥感影像

密西根大学张阳教授受聘中国上海交通大学客座教授(图)

【LeetCode】2. Valid parentheses · valid parentheses

Go language foundation ----- 11 ----- regular expression

Go language foundation ----- 09 ----- exception handling (error, panic, recover)
随机推荐
Redis查看客户端连接
Go language foundation ----- 16 ----- goroutine, GPM model
Screenshot tool snipaste
Huawei s5700 switch initialization and configuration SSH and telnet remote login methods
Go language foundation ----- 11 ----- regular expression
jsutlis
Go language foundation ----- 08 ----- interface
Go language foundation ----- 19 ----- context usage principle, interface, derived context (the multiplexing of select can be better understood here)
Pat class a 1032 sharing
E: 无法定位软件包 ros-melodic-desktop-full
Go language foundation ----- 18 ----- collaboration security, mutex lock, read-write lock, anonymous lock, sync Once
Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework
PHP wechat red packet grabbing algorithm
How to configure GDAL under idea
Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task
haproxy+keepalived集群搭建02
Analysis of the problems of the 11th Blue Bridge Cup single chip microcomputer provincial competition
Huawei switches are configured with SSH login remote management switches
Technical dry goods | some thoughts on the future of AI architecture
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03