2

我试图在不使用任何 HTML 标记的情况下禁用 Windows Phone 8 上 WebBrowser 控件的滚动和缩放。我发现了一些关于此的文章,但它们都是针对 Windows Phone 7 的,我无法使代码在 WP8 上运行。我已经尝试了下面文章中描述的内容,但它不适用于 WP8:

http://www.scottlogic.co.uk/blog/colin/2011/11/suppressing-zoom-and-scroll-interactions-in-the-windows-phone-7-browser-control/

我也尝试过设置ScrollViewer.VerticalScrollBarVisibility="Disabled"and ScrollViewer.HorizontalScrollBarVisibility="Disabled",但我仍然可以滚动和缩放。

我不知道该怎么办了,我开始认为这在 WP8 上是不可能的。有谁知道如何解决这个问题?

提前致谢!

4

3 回答 3

3

你试过这个 CSS 属性吗?

-ms-touch-action: none;
于 2013-11-07T16:58:38.987 回答
0

您可以为此使用 WebBrowserHelper 类

创建 WebBrowserHelper 类的实例

public Header()
{
InitializeComponent();
new WebBrowserHelper(wbHeaderBrowser, strHeaderUri);
new WebBrowserHelper(wbFooterBrowser, strFooterUri);
}

WebBrowserHelper.cs

using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using LinqToVisualTree;
using Microsoft.Phone.Controls;

/// <summary>
/// Suppresses pinch zoom and optionally scrolling of the WebBrowser control
/// </summary>
public class WebBrowserHelper
{
  private WebBrowser _browser;

  /// <summary>
  /// Gets or sets whether to suppress the scrolling of
  /// the WebBrowser control;
  /// </summary>
  public bool ScrollDisabled { get; set; }

  public WebBrowserHelper(WebBrowser browser)
  {
    _browser = browser;
    browser.Loaded += new RoutedEventHandler(browser_Loaded);
  }

  private void browser_Loaded(object sender, RoutedEventArgs e)
  {
    var border = _browser.Descendants<Border>().Last() as Border;

    border.ManipulationDelta += Border_ManipulationDelta;
    border.ManipulationCompleted += Border_ManipulationCompleted;
  }

  private void Border_ManipulationCompleted(object sender,
                                            ManipulationCompletedEventArgs e)
  {
    // suppress zoom
    if (e.FinalVelocities.ExpansionVelocity.X != 0.0 ||e.FinalVelocities.ExpansionVelocity.Y != 0.0 ||(ScrollDisabled && e.IsInertial))
  }

  private void Border_ManipulationDelta(object sender,
                                        ManipulationDeltaEventArgs e)
  {
    // suppress zoom
    if (e.DeltaManipulation.Scale.X != 0.0 ||
        e.DeltaManipulation.Scale.Y != 0.0)
      e.Handled = true;

    // optionally suppress scrolling
    if (ScrollDisabled)
    {
      if (e.DeltaManipulation.Translation.X != 0.0 ||
        e.DeltaManipulation.Translation.Y != 0.0)
        e.Handled = true;
    }
  }
}
于 2013-12-24T06:14:50.960 回答
0

您可以将 IsHitTestVisible 属性设置为 False。

于 2015-10-20T07:32:44.977 回答