次の方法で共有


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.


CHECK OUT THESE ADDITIONAL ZERO-COST RESOURCES.

image

  • Think blue sky with Azure free trial

image

image

Comments

  • Anonymous
    June 06, 2013
    show

  • Anonymous
    May 29, 2014
    How to stop zooming and pinch in WebView for WinRT.?