diff options
author | Vsevolod Kukol <sevo@xamarin.com> | 2016-07-27 19:42:37 +0300 |
---|---|---|
committer | Vsevolod Kukol <sevo@xamarin.com> | 2016-07-27 19:42:37 +0300 |
commit | 95f30dc6a31cad9e09f1d8a17e7dc1face4e773f (patch) | |
tree | 37c3392985b1c7e1f923fe9662e7cde7dd6f66b7 /TestApps | |
parent | 2edea3e49bcc9362f9b90d002ac4a5def42f7a86 (diff) |
[Wpf] Add WebView Emulation mode example
Add an example on how to set different IE emulation
modes for the WPF based WebView backend.
Diffstat (limited to 'TestApps')
-rw-r--r-- | TestApps/WpfTest/Main.cs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/TestApps/WpfTest/Main.cs b/TestApps/WpfTest/Main.cs index fe065a59..feb5e7af 100644 --- a/TestApps/WpfTest/Main.cs +++ b/TestApps/WpfTest/Main.cs @@ -2,6 +2,7 @@ // // Author: // Luís Reis <luiscubal@gmail.com> +// Vsevolod Kukol <sevoku@microsoft.com> // // Copyright (c) 2012 Luís Reis // @@ -34,7 +35,63 @@ namespace WpfTest [STAThread] public static void Main(string[] args) { + /* + WORKAROUND for Xwt.WebView on Windows using WPF: + The WPF WebView Backend is based on System.Windows.Controls.WebView + which runs in IE7 emulation mode by default. This behaviour can only be + changed by modifying the Windows registry, which is not part of the Xwt + API. See https://msdn.microsoft.com/de-de/library/ee330730.aspx#browser_emulation + for more information. + Uncomment the next line to set different IE Emulation modes + */ + //WebViewEmulationMode = IEEmulationMode.IE11; + App.Run (ToolkitType.Wpf); } + + /// <summary> + /// Gets or sets the System.Windows.Controls.WebView Emulation mode + /// </summary> + /// <remarks>This is a simple example on how to change the WebView emulation mode</remarks> + public static IEEmulationMode WebViewEmulationMode + { + get + { + var regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true); + if (regKey == null) + return IEEmulationMode.Default; + + string myProgramName = System.IO.Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location); + var currentValue = regKey.GetValue(myProgramName); + return currentValue != null ? (IEEmulationMode)currentValue : IEEmulationMode.Default; + } + set + { + var regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true); + if (regKey == null) + regKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BEHAVIORS", Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree); + + string executableName = System.IO.Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location); + var currentValue = regKey.GetValue(executableName); + if (currentValue == null || (int)currentValue != (int)value) + regKey.SetValue(executableName, (int)value, Microsoft.Win32.RegistryValueKind.DWord); + } + } + + /// <summary>Internet Explorer Emulation Modes</summary> + /// <remarks>https://msdn.microsoft.com/de-de/library/ee330730.aspx#browser_emulation</remarks> + public enum IEEmulationMode + { + IE7 = 0x00001b58, + IE8 = 0x00001f40, + IE8Force = 0x000022b8, + IE9 = 0x00002328, + IE9Force = 0x0000270f, + IE10 = 0x00002710, + IE10Force = 0x00002711, + IE11 = 0x00002af8, + IE11Force = 0x00002af9, + Default = IE7, + } } } |