WPF关闭应用程序从弹出窗口 [英] WPF Close the application From a popup

查看:79
本文介绍了WPF关闭应用程序从弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图从弹出窗口关闭应用程序。我的想法是,当我点击弹出窗口右上角的关闭按钮时,会显示一条确认消息框,显示应用程序将关闭,然后当他们点击确定按钮时,应用程序将关闭。 />
我试图使用以下命令:
XAML中的


Hi,

I am trying to close the application from a popup. the idea is that when I click on the close button on the top-right of the popup a confirmation-messageBox will be displayed saying "The application will close" and then when they click on the Ok button, the application will shutdown.
I have tried to use the following command:
in the XAML:

behaviours:ApplicationShutDownBehaviour.Closing="{Binding ClosingCommand}">

In the ViewModel:

<pre>private void ApplicationClosing(object obj)
        {
            Application.Current.Shutdown();
        }

        private bool CanApplicationClose(object arg)
        {
                return MessageBox.Show(string.Format("Application will close"), "Confirm", MessageBoxButton.OK,
                                MessageBoxImage.Warning) == MessageBoxResult.OK;

        }



但它无法正常工作,因为只要我点击弹出窗口中的任何按钮,应用程序就会关闭。如果我点击弹出窗口的X(右下角),我只想关闭它。



请有人帮助我吗?


but It is not working because anytime I click on any button in the popup the application closes. and I only want it to close if I click on the X (bottom-right) of the popup.

Please can someone help me?

推荐答案

错误的做法! (并且WPF中没有弹出窗口,有对话框和模态窗口。)



您需要使用<$显示对话框或以模态形式显示窗口c $ c> ShowDialog :

http://msdn.microsoft.com/en-us/library/system.web.httputility.htmlencode.aspx [ ^ ]。



之后完成后,调用代码应该检查结果。使用 Window ,您可以提供并检查您可能设备的任何属性以指示请求某个操作,但标准方式使用属性 DialogResult

http:/ /msdn.microsoft.com/en-us/library/system.windows.window.dialogresult.aspx [ ^ ]。



调用代码的实例是显示并最终关闭后的对话框或窗口。此时,调用代码可以检查结果并相应地执行操作。例如,它可以关闭退出应用程序的应用程序的主窗口: http://msdn.microsoft .com / zh-CN / library / ms597013.aspx [ ^ ]。



这就是全部。非常简单,并且不需要从弹出窗口关闭。



-SA
Wrong approach! (And there are no pop-ups in WPF, there are dialog and modal windows.)

You need to show dialog or show a window in modal form using ShowDialog:
http://msdn.microsoft.com/en-us/library/system.web.httputility.htmlencode.aspx[^].

After it is done, the calling code should check up the result. With Window, you can provide and check up any property you might device to indicate that certain action is requested, but the standard way uses the property DialogResult:
http://msdn.microsoft.com/en-us/library/system.windows.window.dialogresult.aspx[^].

The calling code has the instance of a dialog or a windows after it was shown and eventually closed. At this moment, the calling code can check up the result and act accordingly. For example, it can close the main window of the application of exit the application: http://msdn.microsoft.com/en-us/library/ms597013.aspx[^].

That''s all. Very easy, and no "close from a popup" needed.

—SA


这篇关于WPF关闭应用程序从弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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