首页 > 其他分享 >Material Design WPF DialogHost 实现异步关闭

Material Design WPF DialogHost 实现异步关闭

时间:2023-05-05 23:46:46浏览次数:40  
标签:异步 MySelf IsOpen Material DialogHost Design 关闭 弹窗

在撰写一个按钮处理数据同步的事件时,处理前先弹出一个窗口,告知用户正在处理数据,处理数据后再关闭这个弹窗。

 Button按钮的事件代码原先是这样,预想中是处理一些事情后,可以自动关闭弹窗。DialogHost_MySelf就是DialogHost。

1  this.DialogHost_MySelf.IsOpen = true; 
2   /**
3   处理一些事情
4   */
5  this.DialogHost_MySelf.IsOpen = false; 

但在实际运行中发现,并没有按照预想的那样先弹出后关闭,而是直接不弹窗了。

后来在官方文档中发现有这么一句话,这句话的意思是对话框是异步的,您不得不在代码中去处理它。

 也就是说,在之前的代码中,设置IsOpen为true后,并没有立即执行,而是在等待这个按钮事件完成。结果又碰到了设置IsOpen为false的代码,导致最后也不弹窗。

正确代码执行方式如同下图所示,使用Task+Dispatcher.Invoke来实现异步延时关闭弹窗

 

 1 this.DialogHost_MySelf.IsOpen = true;
 2 
 3 Task.Run(async () =>
 4 {
 5     /**
 6      await 处理一些事情
 7      */
 8  Dispatcher.Invoke(() =>
 9    {
10       this.DialogHost_MySelf.IsOpen = false;
11     });
12  });

 

标签:异步,MySelf,IsOpen,Material,DialogHost,Design,关闭,弹窗
From: https://www.cnblogs.com/lixiaoyutian/p/17375668.html

相关文章

  • The plugin distribution bundles IDE packages 'com.intellij.uiDesigner.core',
    错误描述:TheplugindistributionbundlesIDEpackages'com.intellij.uiDesigner.core','com.intellij.uiDesigner'.BundlingIDEpackagesisconsideredbadpracticeandmayleadtosophisticatedcompatibilityproblems.Considerexcludingthe......
  • Three.js#04#Responsive Design&Scenegraph
    参考https://threejs.org/manual/#en/responsive和https://threejs.org/manual/#en/scenegraph前者主要是说怎样创建一个响应式的three.js应用,就是在变化屏幕大小的时候,画面不会畸形。后者是再说,怎么组合小的组件变成一个大的组件(依赖于一个空组件object3D)下面是示例代码:index.......
  • MaterialSkin
      NuGetGallery|MaterialSkin.22.3.1  NuGet\Install-PackageMaterialSkin.2-Version2.3.1 下载包方式:    Downloadpackage:materialskin.2.2.3.1.nupkg,安装在文件夹下后、程序包源里设置:                ......
  • 05 Real-Time Physically-Based Materials
    1.MicrofacetBRDF1.1菲涅尔项菲涅尔项:反射光线强度与入射角的关系。对于绝缘体而言,观察方向越是平行于平面,反射越强,图像越清晰;因为镜面反射可逆,所以反之亦然。对于金属而言,规律相似,但是变化没有绝缘体那么明显。菲涅尔项的值与角度以及两个介质的折射率有关,可以采用简......
  • Ant Design的基本使用
    title:08-AntDesign的基本使用publish:trueandt的介绍AntDesign是基于React实现,开发和服务于企业级后台产品。支持环境现代浏览器和IE9及以上(需要polyfills)。支持服务端渲染。ElectronElectron(原名为AtomShell)是GitHub开发的一个开源框架。它允许......
  • SystemVerilog for Design Edition 2 Chapter 2
    SystemVerilogforDesignEdition2Chapter2SystemVerilogDeclarationSpacesVerilogonlyhaslimitedplacesinwhichdesignerscandeclarevariablesandotherdesigninformation.SystemVerilogextendsVerilog’sdeclarationspacesinseveralways.These......
  • SystemVerilog for Design Edition 2 Catalog
    SystemVerilogforDesignEdition2CatalogPart10:The2022WilsonResearchGroupFunctionalVerificationStudy-VerificationHorizons(siemens.com)SynthesizableSystemVerilog:BustingtheMyththatSystemVerilogisonlyforVerification(sutherland-......
  • SystemVerilog for Design Edition 2 Chapter 1
    SystemVerilogforDesignEdition2Chapter1IntroductiontoSystemVerilog:ThischapterprovidesanoverviewofSystemVerilog.Thetopicspresentedinthischapterinclude:•TheoriginsofSystemVerilog•TechnicaldonationsthatwentintoSystemVerilog......
  • 快照snapshot与物化视图materializ…
    一、快照1.权限grantcreatesnapshottozjbf;2.创建create  snapshot  SP_TEST refresh    complete     startwithsysdatenextsysdate+5/(24*60*60) as           select  *  from      SELECT*FROMSP_TESTWHERE......
  • 3、题目:Feedback in concept development: Comparing design disciplines
    期刊信息(1)作者:Yilmaz,Seda.(2)期刊:DesignStudies,2016,45:137-158(3)DOI:10.1016/j.destud.2015.12.008(4)ISSN:0142-694X(5)IF:3.853(Q2)研究背景设计反馈是促进学生设计进步的必要教学工具,但很少有研究关注教师的反馈是什么样子的,特别是在跨设计学科方面研......