将 WPF 网页浏览器控件设置为使用 IE10 模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23776951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set WPF webbrowser control to use IE10 mode
提问by Jibin Mathew
How can i set the WPF webbrowser controls to render pages in iE10 mode or the higher version installed on machine . By default if i create a .net 4 or .net 4.5 application on any machine of OS > windows 7 , it renders the html pages in IE7 mode only. (Please correct if i am wrong) How to enable the application to render the html pages in IE10 mode if IE10 installed on target machine ? Any helps
如何设置 WPF 网页浏览器控件以在 iE10 模式或机器上安装的更高版本中呈现页面。默认情况下,如果我在 OS > windows 7 的任何机器上创建 .net 4 或 .net 4.5 应用程序,它只会在 IE7 模式下呈现 html 页面。(如果我错了,请更正)如果目标机器上安装了 IE10,如何启用应用程序以 IE10 模式呈现 html 页面?任何帮助
采纳答案by Jibin Mathew
You can use the registry as described here:
您可以按照此处所述使用注册表:
http://msdn.microsoft.com/en-us/library/ie/ee330730%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/ie/ee330730%28v=vs.85%29.aspx
EDIT: for a better explanation you can read this answer too Will the IE9 WebBrowser Control Support all of IE9's features, including SVG?
编辑:为了获得更好的解释,您也可以阅读此答案 IE9 WebBrowser Control 是否支持 IE9 的所有功能,包括 SVG?
回答by xr280xr
If you don't want to modify the registry and you control the webpage, you can use the
如果您不想修改注册表并控制网页,则可以使用
<meta http-equiv="X-UA-Compatible" content="IE=10">
tag in the document's head. I believe it has to be first or immediately following <title>
in order to work.
文档头部的标签。我相信它必须首先或紧随其后<title>
才能起作用。
回答by Mentor
For WPF webbrowser control use IE11 mode need , for example, in the constructor of the main window, add the following code:
对于WPF网页浏览器控件使用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 += " ( Первый раз запускать с правами админа )";
If you want to see WPF webbrowser control use IE11 mode in DEBUG mode when run from visual studio, you need to add in the registry all progmam "*". This can be done with the following code:
如果你想看到WPF webbrowser控件在从visual studio运行时在DEBUG模式下使用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 += " ( Первый раз запускать с правами админа )";
Checked for windows 10 and visual studio 2015.
检查 Windows 10 和 Visual Studio 2015。
Remark: codes other versions of internet explorer, see here https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation
备注:其他版本的 Internet Explorer 代码,请参见此处https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation