Set WPF webbrowser control to use IE10 mode

主宰稳场 提交于 2019-11-27 09:04:34

You can use the registry as described here:

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?

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.

For WPF webbrowser control use IE11 mode need , for example, in the constructor of the main window, add the following code:

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:

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.

Remark: codes other versions of internet explorer, see here https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!