我该如何设置WPF WebBrowser控件以在机器上安装的IE10模式或更高版本中呈现页面? 默认情况下,如果我在任何操作系统> Windows 7的计算机上创建一个.NET 4或.NET 4.5应用程序,则仅使用IE7模式呈现HTML页面。(如有错误请指出)。 如果目标机器安装了IE10,如何启用应用程序以在IE10模式下呈现HTML页面?
我该如何设置WPF WebBrowser控件以在机器上安装的IE10模式或更高版本中呈现页面? 默认情况下,如果我在任何操作系统> Windows 7的计算机上创建一个.NET 4或.NET 4.5应用程序,则仅使用IE7模式呈现HTML页面。(如有错误请指出)。 如果目标机器安装了IE10,如何启用应用程序以在IE10模式下呈现HTML页面?
如果您不想修改注册表,并且您控制网页,则可以使用
<meta http-equiv="X-UA-Compatible" content="IE=10">
我认为文档头部的标签必须放在<title>
标签之前或紧随其后才能起作用。
如果需要在WPF WebBrowser控件中使用IE11模式,可以在主窗口的构造函数中添加以下代码:
var pricipal = new System.Security.Principal.WindowsPrincipal(
System.Security.Principal.WindowsIdentity.GetCurrent());
if(pricipal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) {
RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
(@"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
string myProgramName = Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);
var currentValue = registrybrowser.GetValue(myProgramName);
if (currentValue == null || (int)currentValue != 0x00002af9)
registrybrowser.SetValue(myProgramName, 0x00002af9, RegistryValueKind.DWord);
}
else
this.Title += " ( Первый раз запускать с правами админа )";
如果您想在Visual Studio中运行时看到WPF WebBrowser控件使用IE11模式,需要在注册表中添加所有程序的“*”项。以下是相关代码:
var pricipal = new System.Security.Principal.WindowsPrincipal(
System.Security.Principal.WindowsIdentity.GetCurrent());
if (pricipal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) {
RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
(@"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
var currentValue = registrybrowser.GetValue("*");
if (currentValue == null || (int)currentValue != 0x00002af9)
registrybrowser.SetValue("*", 0x00002af9, RegistryValueKind.DWord);
}
else
this.Title += " ( Первый раз запускать с правами админа )";
已在Windows 10和Visual Studio 2015上检查。
备注:如果需要其他版本Internet Explorer的代码,请查看此处。
string appName = System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetExecutingAssembly().Location);
string appNameExe = appName + ".exe";
string appVSNameExe = appName + ".vshost..exe";
然后将当前值应用于appNameExe和appVSNameExe,它们都可以正常工作,而无需强制使用* all。 - Luishg