Created
May 4, 2012 18:19
-
-
Save germboy/2596720 to your computer and use it in GitHub Desktop.
WebBrowserHelper file for disabling WP7 pinch/zoom & scroll-snapback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Linq; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Input; | |
using LinqToVisualTree; | |
using Microsoft.Phone.Controls; | |
namespace App.Util | |
{ | |
/// <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) | |
e.Handled = true; | |
} | |
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; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment