最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
wpf单例模式只打开一个窗口例子
时间:2022-06-25 08:42:44 编辑:袖梨 来源:一聚教程网
WPF 单例窗口Close()后再Show()会报错,Close会调用Dispose,资源会马上被释放,ShowDialog()的情形是一样的。

重载OnClosing(CancelEventArgs e)方法,使用Hide()方法。
| 代码如下 | 复制代码 |
| private static GHXTestControl _instance; private static readonly object ObjLok = new object(); public static GHXTestControl Instance() { lock (ObjLok) { return _instance ?? (_instance = new GHXTestControl()); } } /// /// protected override void OnClosing(CancelEventArgs e) { Hide(); e.Cancel = true; } private GHXTestControl() { InitializeComponent(); } | |
调用:
| 代码如下 | 复制代码 |
|
private WindowPages.GanHuaxue.GHXTestControl _GHXControl; private void Click() //WindowPages.GanHuaxue.GHXTestControl t = new WindowPages.GanHuaxue.GHXTestControl(); } | |
相关文章
- twitter网页版一键登录-twitter官网网页版 03-22
- Mail.ru官网如何快速登录-Mail.ru官网登录入口在哪 03-22
- 免费的无限资源游戏前十名 流行的无限资源游戏大全2026 03-22
- 《幻想之刃》深渊追猎收藏品养成攻略-详细玩法解析 03-22
- 御兽岛新手初始御兽选择推荐-新手必看初始御兽解析 03-22
- 夸克网盘网页版直达-夸克浏览器云存储一键登录 03-22