可以使用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;
}
}
}
你是否嘗試過這個帖子? [禁用縮放/平移/滾動爲web瀏覽器控件的功能] [1] [1]:http://stackoverflow.com/questions/11462611/disabling-the-zoom-pan-scroll - 功能爲網頁瀏覽器控制 –
這是我發佈在我的問題中的鏈接完全相同的解決方案。它不適用於WP8,僅適用於WP7。控制結構改變了。 'Loaded'事件不起作用,'LayoutUpdated'給我一個例外,它找不到指定的'Border'。 –
我在調查此問題時發現,我的WP8設備遵守您在http://www.scottlogic.com鏈接的問題聲明中描述的指令/blog/2011/11/17/suppressing-zoom-and-scroll-interactions-in-the-windows-phone-7-browser-control.html。 你最近試過嗎?您可能會在頁面中顯示某些內容,導致它無法正常工作。 –