WinRT WebView and Zoom Level

Earlier this week I was asking myself “How can I change the Zoom level of a WinRT WebView”?

When the WebView control has the focus you can zoom in/out just like you do in IE10: by using keyboard CTRL+ , CTRL-.

But can this be one from code? Not directly in managed code, but you can use the following workaround IF you have full control of the content and are able to inject css/script.

CSS: In your HTML just add: <style type="text/css"> body { zoom:100%; } </style>

HTML: Also in your HTML, include this script: function setZoomLevel(newZoom) { document.styleSheets[0]['rules'][0].style['zoom'] = newZoom; } 

C#: Add this helper-method: private void SetZoomLevel(int level) { string slevel = string.Format("{0}%", level); webBrowser.InvokeScript("setZoomLevel", slevel); }

C#: And final simple call: SetZoomLevel(200);  to adjust the zoom level.

This will produce the same zoom effect as if you were using the zoom slider.

Again, this method ONLY works if you have full control of the HTML code.



  • Think blue sky with Azure free trial



Comments (2)
  1. Jitendra Jadav says:

    How to stop zooming and pinch in WebView for WinRT.?

Comments are closed.

Skip to main content