1

I'm developing an App for WP8 using Visual Studio 2013. I used the WPToolkit to integrate the WebBrowser control.

I'm displaying static information in my WebBrowser control with changes just to the text using the following function.

Private Function CreateHtmlDocument() As String

    Dim strHtmlDoc As String = ""

    strHtmlDoc = "<html>"
    strHtmlDoc = strHtmlDoc & "<head>"
    strHtmlDoc = strHtmlDoc & "<meta name='viewport' content='width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=no';>"
    strHtmlDoc = strHtmlDoc & "</head>"
    strHtmlDoc = strHtmlDoc & "<style type='text/css'>"
    strHtmlDoc = strHtmlDoc & "body{ -ms-touch-action: none !important; -ms-content-zooming:none; -ms-scroll-limit-y-max :auto;}"
    strHtmlDoc = strHtmlDoc & "</style>"
    strHtmlDoc = strHtmlDoc & "<body>"
    strHtmlDoc = strHtmlDoc & "<span style='color:#bf2e1a'><b><font face='Times New Roman' size='3'>" & clsGlobalVariables.branch & "</font></b></span>"
    strHtmlDoc = strHtmlDoc & "<br> <span style='color:#c1481a'><font face='Times New Roman' size='2'>" & clsGlobalVariables.company_name & "<br> (Legal Name : " & clsGlobalVariables.legal_name & ")</font></span>"
    strHtmlDoc = strHtmlDoc & "<br> <span style='color:#878270'><p align='left'><font face='Arial' size='2'>" & clsGlobalVariables.address & "</font></p> </span>"
    strHtmlDoc = strHtmlDoc & "<span style='color:#878270'><font face='Arial' size='2'>Tel &nbsp;&nbsp;&nbsp;&nbsp;:</span> <span style='color:blue'>" & clsGlobalVariables.telephone & "</font></span>"
    strHtmlDoc = strHtmlDoc & "<br> <span style='color:#878270'><font face='Arial' size='2'>Fax &nbsp;&nbsp;&nbsp;:</span> <span style='color:blue'>" & clsGlobalVariables.fax & "</font></span>"
    strHtmlDoc = strHtmlDoc & "<br> <span style='color:#878270'><font face='Arial' size='2'>Email&nbsp;:</span> <span style='color:blue'>" & clsGlobalVariables.email & "</font></span>"
    strHtmlDoc = strHtmlDoc & "<br>"
    strHtmlDoc = strHtmlDoc & "<br>"
    strHtmlDoc = strHtmlDoc & "</body>"
    strHtmlDoc = strHtmlDoc & "</html>"


    Return strHtmlDoc

End Function

Unfortunately, I can't seem to disable Pinch Zoom. Thankfully, double-tap zoom doesn't work. Also, the scroll is bugged in that it scrolls beyond my data and shows blank space in my control.

Some Image Links(Still don't have 10 Rep) -

http://i.stack.imgur.com/eifhn.jpg      - How it looks normally.
http://i.stack.imgur.com/0panl.jpg      - It zooms too much.
http://i.stack.imgur.com/znf5y.jpg      - It scrolls way below the text.

I already tried http://www.scottlogic.com/blog/2011/11/17/suppressing-zoom-and-scroll-interactions-in-the-windows-phone-7-browser-control.html . It doesn't work for WP8.

My XAML -

 <Grid HorizontalAlignment="Left" Height="320" Margin="10,274,0,0" Grid.Row="1" VerticalAlignment="Top" Width="460">
        <phone:WebBrowser x:Name="webBrowser" HorizontalAlignment="Left" Height="320" IsScriptEnabled="True" VerticalAlignment="Top" Width="460" BorderThickness="2" BorderBrush="OrangeRed" ScrollViewer.VerticalScrollBarVisibility="Auto"/>
 </Grid>
4

2 回答 2

0

这是一个密封的类,所以如果你真的想实现这一点,那么你需要遍历 VisualTree 才能到达正确的容器。

然后只是一个小解决方法:(禁用缩放,但启用滚动)

硬编码值

<ScrollViewer>
    <phone:WebBrowser x:Name="my_wb" Height="1000" IsHitTestVisible="False"></phone:WebBrowser>
</ScrollViewer>

如果您知道如何将 JS 值传递回调用应用程序,您可以完美地调整 WebBrowser 的大小。

<ScrollViewer>
    <phone:WebBrowser x:Name="my_wb" Height="{Binding HeightOfRenderHTMLpage}" IsHitTestVisible="False"></phone:WebBrowser>
</ScrollViewer>
于 2014-09-08T08:17:35.070 回答
0

上个月我遇到了同样的问题(我认为),这是我的解决方案(在 C# 中)。

将 IsHitTestVisible 设置为 false 以禁用与用户的所有交互并启用 IsScriptEnabled 为 true 的脚本

XAML

<ScrollViewer>
  <Grid>
      <Grid.RowDefinitions>
          <RowDefinition
              Height="auto" />
          <RowDefinition
              Height="auto" />
          <RowDefinition
              Height="auto" />
      </Grid.RowDefinitions>
      <TextBlock
          Grid.Row="0"
          x:Name="Subject" />
      <TextBlock
          Grid.Row="1"
          x:Name="Date" />
      <phone:WebBrowser
          Grid.Row="2"
          ScriptNotify="browser_ScriptNotify"
          x:Name="browser"
          IsHitTestVisible="False"
          IsScriptEnabled="True" />
  </Grid>
</ScrollViewer>

在将 HTML 设置为浏览器之前,使用 bodyheight 回调注入 javascript

C#

// preparing HTML page with some viewport settings and JS callback to c#
private string PrepareHtml(string body)
{
    return @"<!DOCTYPE html>
             <html>
                <head>
                    <meta name=""viewport"" content=""width=432, initial-scale=1, maximum-scale=1, user-scalable=0, target-densitydpi=device-dpi"" />
                </head>
                <body>
                    " + body + @"

                    <script type=""text/javascript"">

                        window.external.notify(document.body.clientHeight.toString());

                    </script>
                </body>
            </html>";
}

收到客户端高度通知时,设置浏览器高度

C#

void browser_ScriptNotify(object sender, NotifyEventArgs e)
{
    int o;
    if (int.TryParse(e.Value, out o))
    {
        browser.Height = o;
    }
}

希望能帮助到你

于 2014-09-08T10:03:21.630 回答