Set WPF webbrowser control to use IE10 mode

北战南征 提交于 2019-12-17 09:51:33

问题


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


回答1:


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?




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/23776951/set-wpf-webbrowser-control-to-use-ie10-mode

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