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?



 1 条回答