博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF判断当前窗体是否为模态
阅读量:7136 次
发布时间:2019-06-28

本文共 705 字,大约阅读时间需要 2 分钟。

原文:

WPF判断当前窗体是否为模态
 
1、使用System.Windows.Interop.ComponentDispatcher.IsThreadModal来判断
参照:
注意事项:
        参照:
        1、Works not immediately after ShowModal is called. Some events still cannot tell if modal
        2、This doesn't work if a modal dialog is showing this modeless dialog!
2、使用反射
eg:新建一个拓展方法
1 public static bool IsModal(this Window window)2 {3     return(bool)typeof(Window).GetField("_showingAsDialog", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(window);4 }
 
改进为:
1 public static bool IsModal(this Window window)2 {3     var filedInfo=typeof(Window).GetField("_showingAsDialog", BindingFlags.Instance | BindingFlags.NonPublic);4 5     return filedInfo!=null&&(bool)filedInfo.GetValue(window);6 }

 

参照:
 
推荐第二种

转载地址:http://jutrl.baihongyu.com/

你可能感兴趣的文章
Gym-100676F Palindrome
查看>>
DS博客作业03--栈和队列
查看>>
Windows 10 to Go
查看>>
关于函数的原型对象笔记
查看>>
转:深入浅出空间索引:为什么需要空间索引
查看>>
IC卡读卡器web开发,支持IE,Chrome,Firefox,Safari,Opera等主流浏览 器
查看>>
CSS3: box-sizing 属性的简单认识
查看>>
Python3.2 --- Print函数用法
查看>>
常用工具说明--Java的常用工具
查看>>
C++中几个值得分析的小问题(1)
查看>>
【LeetCode 104_二叉树_遍历】Maximum Depth of Binary Tree
查看>>
Android zxing扫描二维码 为什么有些机型扫描不出来或者很慢?
查看>>
js-循环执行一个函数
查看>>
HDU 4720 Naive and Silly Muggles (简单计算几何)
查看>>
linux终端快捷键
查看>>
基础数据类型的补充和深浅copy
查看>>
20160327javaweb 之JSP入门
查看>>
NFS 挂载时提示:Root-NFS: Server returned error -13
查看>>
python整理&&集合学习
查看>>
深入浅出Node.js (10) - 测试
查看>>