0

app.xaml 中的 application_exit 和 session_ending 事件无济于事。

有什么办法可以做到这一点?

4

1 回答 1

0

XBAP 应用程序忽略 session_ending 事件但是 Exit 事件是,但我看不到在此事件中取消退出的方法。但是,为什么不让您的退出按钮调用一个方法来请求关闭,如果是,请在此处明确关闭应用程序,或者不

 [DllImport("user32", ExactSpelling = true, CharSet = CharSet.Auto)]
        private static extern IntPtr GetAncestor(IntPtr hwnd, int flags);
        [DllImport("user32", CharSet = CharSet.Auto)]
        private static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam); 
        private void exitButton_Click(object sender, RoutedEventArgs e)
        {

            if (MessageBox.Show("Are you Sure you want to Exit?", "Confirm", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                // This will Shut entire IE down
                WindowInteropHelper wih = new WindowInteropHelper(Application.Current.MainWindow);
                IntPtr ieHwnd = GetAncestor(wih.Handle, 2);
                PostMessage(ieHwnd, 0x10, IntPtr.Zero, IntPtr.Zero);       

                // Singularly will just shutdown single tab and leave white screen, however with above aborts the total IE shutdown
                // and just shuts the current tab
                Application.Current.Shutdown();
            }          
        }

你还需要这些

使用 System.Windows.Interop;使用 System.Runtime.InteropServices;

于 2010-06-27T08:11:16.250 回答