如何关闭具有选项卡控件的窗口 [英] How Do I Close My Window Having Tab Controls

查看:96
本文介绍了如何关闭具有选项卡控件的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我对wpf很新。

在我的应用程序中,我有一个启动窗口,我们将从主窗口进入。在这个主窗口中,我们有标签控件。在每个选项卡下,我们有不同的控件集。

现在在我的功能区菜单中,我想要包含一个关闭此主窗口的按钮,并且必须返回到我的启动窗口。

我该怎么办?



请赐教。



我写了以下代码在我的Mainwindow.xaml中:



< ribbon:ribbongroup header =到主屏幕xmlns:ribbon =#unknown> < ribbon:ribbonbutton largeimagesource =Images \Go.ico>

Label =Go BackCommand ={Binding GoBack_L1}/>



我在.cs文件中实现了这个函数,它是我的startupWindow的datacontext。

函数被调用。我hvae创建了一个启动窗口的对象,并为startupWindow调用函数Close()。但它不起作用,strtupWIndow没有关闭。请让我知道解决方案。

Hi All,
I am very new to wpf.
In my application i have a startup window and from this we will be going to the Mainwindow. In this main window we have tab controls. Under each tab we have different set of controls.
Now in my ribbon menu i want to include a button that will close this Mainwindow and has to go back to my Startup window.
How can i do this??

Please sugget.

I have written the following code in my Mainwindow.xaml:

<ribbon:ribbongroup header="To Main Screen" xmlns:ribbon="#unknown"> <ribbon:ribbonbutton largeimagesource="Images\Go.ico">
Label="Go Back" Command="{Binding GoBack_L1}" />

I have implemented this function in the .cs file which is the datacontext to my startupWindow.
The function is getting called. I hvae created an object of my startup window and calling the function Close() for startupWindow. But its not working, the strtupWIndow is not closing. Please let me know the solution.

推荐答案

要关闭窗口,请使用 Window.Close

http://msdn.microsoft .com / zh-cn / library / system.windows.window.close(v = vs.110).aspx [ ^ ]。



请查看我对这个问题的评论,在那里我解释说在某些情况下你需要隐藏一个窗口而不是关闭,以便稍后再显示:

http://msdn.microsoft.com/en-us/library/system.windows .window.hide(v = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.window.show(V = VS。 110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog(v = vs.110)的.aspx [ ^ ]。



如果你需要隐藏窗口,你可能遇到的问题是:F4或点击非客户端窗口关闭control [x]仍将关闭窗口而不是隐藏。您需要通过覆盖 Window.OnClosing 来阻止它(或者,您可以处理事件 Closing ):

http:// msdn.microsoft.com/en-us/library/system.windows.window.onclosing%28v=vs.110%29.aspx [ ^ ]。



为防止关闭,您需要通过设置属性 CancelEventArguments.Cancel 取消它(将事件参数作为参数传递给被覆盖的方法)为true:

http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs。取消(v = vs.110).aspx [ ^ ]。



要隐藏窗口,请致电来自事件处理程序的Window.Hide



-SA
To close window, use Window.Close:
http://msdn.microsoft.com/en-us/library/system.windows.window.close(v=vs.110).aspx[^].

Please see my comment to the question, where I explain that in some cases you need to hide a window instead of closing, to later show it again:
http://msdn.microsoft.com/en-us/library/system.windows.window.hide(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.window.show(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog(v=vs.110).aspx[^].

If you need to hide the window, the problem you may face is this: F4 or the click on the non-client window close control [x] will still close the window instead of hiding. You will need to prevent it by overriding Window.OnClosing (alternatively, you could handle the event Closing):
http://msdn.microsoft.com/en-us/library/system.windows.window.onclosing%28v=vs.110%29.aspx[^].

To prevent closing, you will need to cancel it by setting the property CancelEventArguments.Cancel (with the event arguments passed as a parameter to your overridden method) to true:
http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.cancel(v=vs.110).aspx[^].

To hide the window, call Window.Hide from the event handler.

—SA


这篇关于如何关闭具有选项卡控件的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆