我完全信任使用XBAP应用程序。当我点击一个按钮时,我需要关闭托管XBAP的浏览器。我怎样才能做到这一点? Application.Currenty.ShutDown()
仅关闭应用程序,将浏览器留空。
答案 0 :(得分:5)
答案 1 :(得分:4)
修改强> 我的错误,这是一个问题的主题 - http://social.msdn.microsoft.com/forums/en-US/wpf/thread/21c88fed-c84c-47c1-9012-7c76972e8c1c
更具体(此代码需要完全信任安全设置)
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);
}
答案 2 :(得分:1)
这很棒!但是它也会关闭所有IE,包括任何打开的标签
你不会相信这一个,但如果你也做了一个Application.Current.Shutdown():在上面之后它会中止整个IE关闭并只关闭应用程序选项卡。
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();
}