Eric.M
Eric.M

Reputation: 857

Disable scroll & Zoom in Windows Phone 8 WebBrowser

I'm trying to disable the scrolling and zooming on the WebBrowser control on Windows Phone 8 without using any HTML tags. I've found a few articles about this but they're all for Windows Phone 7 and I cannot make the code work on WP8. I've tried what is described in the article below, but it doesn't work on WP8:

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

I've also tried setting ScrollViewer.VerticalScrollBarVisibility="Disabled"and ScrollViewer.HorizontalScrollBarVisibility="Disabled", but I can still scroll and zoom.

I don't know what to do anymore, I'm starting to think it's not possible on WP8. Does anyone know how to solve this issue?

Thanks in advance!

Upvotes: 2

Views: 4296

Answers (3)

ilke.uygun
ilke.uygun

Reputation: 129

You can set IsHitTestVisible property to False.

Upvotes: 0

Rashad Valliyengal
Rashad Valliyengal

Reputation: 3162

you can use the WebBrowserHelper class for this

Created instance of WebBrowserHelper class

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;
    }
  }
}

Upvotes: 0

Andreas Zita
Andreas Zita

Reputation: 7560

Have you tried this CSS-property?

-ms-touch-action: none;

Upvotes: 3

Related Questions