Created
August 29, 2012 15:12
-
-
Save chgeuer/3514112 to your computer and use it in GitHub Desktop.
Change zoom level in a Windows 8 WebView control by injecting JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| zoomLevel.TextChanged += (s, e) => | |
| { | |
| Func<WebView, double, bool> zoom = (wv, zoomPercentage) => | |
| { | |
| var script = string.Format( | |
| "(function () {{ document.styleSheets[0]['rules'][0].style['zoom'] = {0}; }})();", zoomPercentage); | |
| try | |
| { | |
| var result = wv.InvokeScript("eval", new string[] { script }); | |
| return true; | |
| } | |
| catch (Exception ex) | |
| { | |
| var notReady = ex.HResult == 0x80020101; | |
| if (notReady) return false; | |
| throw; | |
| } | |
| }; | |
| double zl; | |
| if (double.TryParse(zoomLevel.Text, out zl)) | |
| { | |
| zoom(webView, zl); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment