Does the WPF WebBrowser control depend on the version of IE that is installed on the user's machine, or does it use a separate library that is consistent across machines? I've read that it only renders in IE7 mode, but I want to make sure there wouldn't be any issues with a user who either doesn't have IE installed or is still on IE6 for some reason.
问题:
回答1:
The MSDN remarks for WebBrowser indicate it rehosts the IE ActiveX control:
The WebBrowser control internally instantiates the native WebBrowser ActiveX control.
The WebBrowser ActiveX control is better known as Shdocvw.dll
. This in turn wraps Mshtml.dll
, and probably other DLL's given your environment. One caveat of rehosting this control is its setting for Browser Emulation:
For applications hosting the WebBrowser Control, the default value is
7000
. To control the value of this feature by using the registry, add the name of your executable file to the following setting and set the value to match the desired setting.
0x7000
means IE7 compatibility mode. Therefore, if you would like your WPF application to render using some other mode you need to update the registry, as adapted from this example:
[HKEY_LOCAL_MACHINE\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION]
"MyApplication.exe" = dword:2328
回答2:
I created a WPF app with a WebBrowser Control on a machine with IE11 and got this user agent string:
user agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3; .NET CLR 1.1.4322)
I created a WPF app with a WebBrowser Control on a machine with IE10 and got this user agent string:
user agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)
Trident/7.0 indicates IE11 and Trident/6.0 indicates IE10. More about user-agent strings.
The system with IE10 also had the page render differently than the system with IE11. I also verified this with the standalone IE browsers on each system.
I've yet to try it on a system WITHOUT IE or a system running IE6, but it seems that WebBrowser control is related to the version of IE currently installed on the system.