wpf – 如何停止每次打开一个新窗口?
发布时间:2020-12-13 22:37:53 所属栏目:Windows 来源:网络整理
导读:我有一个 WPF应用程序,在该应用程序中,单击菜单项会打开一个窗口.如果在窗口打开时再次单击相同的菜单项,则会打开一个新窗口,但我不希望每次都打开一个新窗口. 我需要的是,如果窗口已经打开,则应该关注相同的窗口而不是新窗口. 解决方法 //First we must cre
我有一个
WPF应用程序,在该应用程序中,单击菜单项会打开一个窗口.如果在窗口打开时再次单击相同的菜单项,则会打开一个新窗口,但我不希望每次都打开一个新窗口.
我需要的是,如果窗口已经打开,则应该关注相同的窗口而不是新窗口. 解决方法//First we must create a object of type the new window we want the open. NewWindowClass newWindow; private void OpenNewWindow() { //Check if the window wasn't created yet if (newWindow == null) { //Instantiate the object and call the Open() method newWindow= new NewWindowClass(); newWindow.Show(); //Add a event handler to set null our window object when it will be closed newWindow.Closed += new EventHandler(newWindow_Closed); } //If the window was created and your window isn't active //we call the method Activate to call the specific window to front else if (newWindow != null && !newWindow.IsActive) { newWindow.Activate(); } } void newWindow_Closed(object sender,EventArgs e) { newWindow = null; } 我认为这可以解决你的问题. ATT, (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- 在Windows Server 2008上挂载ISO
- .net – 带有验证和取消按钮的消息框
- Windows10鼠标指针不停转圈的罪魁祸首:搜狗输入
- windows-phone-7 – WP7政策检查
- Windows Workflow Foundation(WF)的最佳资源是什
- windows-7 – Windows 7 – 提升的命令提示符上下
- windows-phone-8 – Windows Phone 8网络信息
- windows – WriteProcessMemory ERROR_PARTIAL_C
- windows-server-2003 – 是否有自动整理来自Perf
- windows-7 – 如何从Windows 7 / Vista格式化为F
热点阅读