Xbap应用程序:当用户关闭浏览器或浏览器选项卡时,如何提示用户确认退出?

时间:2009-10-07 09:09:43

标签: browser xbap exit

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

有没有办法实现这个目标?

1 个答案:

答案 0 :(得分:0)

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

 [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;