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 に答える