【问题标题】:How to reset UWP WebView's content zoomfactor如何重置 UWP WebView 的内容缩放因子
【发布时间】:2017-06-13 04:09:09
【问题描述】:

我正在尝试将 c# UWP 中 web 视图的内容缩放因子重置为 1 或 100%。

我的问题是如何做到这一点?

  • 有没有办法通过 c# 告诉 webview 本身缩减到 1.0?

点赞webView.ContentScale = 1.0;

  • 我必须在 html 中调用什么来告诉它缩放回 100%?

就像我会这样做来执行点击

webView.InvokeScriptAsync("eval", new string[] { "document.elementFromPoint(" + 555 + ", " + 355 + ").click();" });

如果您知道如何在 html / js 中重置缩放因子,它也会对我有所帮助。我会通过评估添加该代码并调用它。

信息:Microsoft Edge 渲染引擎用于这些 web 视图。

我不想只是重新加载页面,因为可能会有一些用户更改,然后这些更改可能会丢失。

来自德国的亲切问候。

【问题讨论】:

    标签: javascript c# html uwp


    【解决方案1】:

    有没有办法通过 c# 告诉 webview 本身缩减到 1.0?

    恐怕目前还没有这样的方法可以直接设置WebView的内容比例。

    如果您知道如何在 html / js 中重置缩放因子,它也会对我有所帮助。我会通过评估添加该代码并调用它。

    如你所想,我们可以在WebView 将加载的页面上添加一个Javascript 函数,并通过InvokeScriptAsync 方法调用该函数。我们可以将zoom 属性设置为该函数中的样式,以根据需要重置缩放系数。例如,我们将以下 HTML 加载到 WebView,并创建了 ZoomFunction

    <!DOCTYPE html>
    
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script type="text/javascript">
            function ZoomFunction(Percentage) {
                var mybody = document.getElementById("mybody");         
                mybody.style.zoom = Percentage + "%";
            }
        </script>
    </head>
    <body id="mybody" style="margin:0px;padding:0px; overflow:hidden;zoom:50%"> 
          This content is shown for zoom in and out. 
    </body>
    </html>
    

    这样我们就可以通过调用脚本来将内容缩放到 100%,如下所示:

     await MyWebView.InvokeScriptAsync("eval", new string[] { "ZoomFunction(100);" });
    

    更多详情请参考How to zoom in/out the content in WebView in Universal Windows Platform

    【讨论】:

    猜你喜欢
    • 2019-02-03
    • 2017-04-08
    • 2014-09-18
    • 2016-05-20
    • 1970-01-01
    • 2016-11-29
    • 2020-03-03
    • 1970-01-01
    • 2017-06-05
    相关资源
    最近更新 更多