我完全信任使用XBAP应用程序.当我点击一个按钮时,我需要关闭托管XBAP的浏览器.我怎样才能做到这一点?Application.Currenty.ShutDown()仅关闭应用程序,将浏览器留空.
我知道这是一个非常古老的问题,但如果有人遇到这个问题,这里有一个更简单的解决方案,只关闭一个标签.
Environment.Exit(0);
Run Code Online (Sandbox Code Playgroud)
资料来源:微软论坛
编辑: 我的错误,这是一个与您的问题有关的线程 - 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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3302 次 |
| 最近记录: |