Let's Chat! Every Tuesday & Thursday 2:00PM EST Let's Build Something Mobile! Let's Build Something Windows! Making Solutons Go Up! Up! Up! Helping Turn Ideas Into Cash! Getting Students Future Ready!

WinRT WebView and Zoom Level

WinRT WebView and Zoom Level

  • Comments 1

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

Leave a Comment
  • Please add 1 and 7 and type the answer here:
  • Post
Page 1 of 1 (1 items)