tags:

views:

205

answers:

1

application_exit and session_ending event in app.xaml cannot help.

Is there any way to achieve this?

A: 

The session_ending event is ignored for XBAP applications However the Exit event is, but I cant see a way to cancel the exit in this event. Howevere, why not just have your Exit Button call a method to ask for shutdown, and if YES, explicitly shut the app down here, or not

 [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();
            }          
        }

you will also need these

using System.Windows.Interop; using System.Runtime.InteropServices;

PrimeTSS