How to close a browser from XBAP?

I use the XBAP application in full trust. I need to close the browser that hosts XBAP when I click the button. How can i achieve this? Application.Currenty.ShutDown() closes the application only when the browser is closed.

+4
source share
3 answers

EDIT: My mistake, here is the thread with your problem - http://social.msdn.microsoft.com/forums/en-US/wpf/thread/21c88fed-c84c-47c1-9012-7c76972e8c1c

and be more specific ( full trust settings are required for this code)

 using System.Windows.Interop; using System.Runtime.InteropServices; [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 button1_Click(object sender, RoutedEventArgs e) { WindowInteropHelper wih = new WindowInteropHelper(Application.Current.MainWindow); IntPtr ieHwnd = GetAncestor(wih.Handle, 2); PostMessage(ieHwnd, 0x10, IntPtr.Zero, IntPtr.Zero); } 
+3
source

I know this is a really old question, but if anyone has this problem, here is a simpler solution that only closes one tab.

 Environment.Exit(0); 

Source: Microsoft Forums

+5
source

It's great !, but it also disables all IE, including any open tabs.

You did not believe this, but if you also run Application.Current.Shutdown (): after that it will stop IE from completely closing and just close the application tab.

  private void exitButton_Click(object sender, RoutedEventArgs e) { // 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(); } 
+1
source

All Articles