Windows phone - Avoid scrolling of Web browser control placed inside scroll viewer

↘锁芯ラ 提交于 2019-12-22 11:25:02

问题


I have to show a web browser inside a scroll viewer in windows phone application, with these requirements :

  1. Web browser height should be adjusted based on its content.
  2. Web browser scrolling should be disabled, ( when user scrolls within web browser, scrolling of scroll viewer should take place )
  3. Web browser can do pinch-zoom and navigate to links inside its content.

    How can I implement that? Any links or samples is greatly appreciated.


回答1:


I'm using code like this. Attach events to the Border element in the Browser control tree (I'm using Linq to Visual Tree - http://www.scottlogic.co.uk/blog/colin/2010/03/linq-to-visual-tree/).

        Browser.Loaded += 
            (s,e)=>
                {
                    var border = Browser.Descendants<Border>().Last() as Border;

                    if (border != null)
                    {
                        border.ManipulationDelta += BorderManipulationDelta;
                        border.ManipulationCompleted += BorderManipulationCompleted;
                        border.DoubleTap += BorderDoubleTap;
                    }
                };

Further more the implementation I'm using is to prevent pinch and zoom, something you want to have working. Though this should help you in the right direction.

private void BorderDoubleTap(object sender, GestureEventArgs e)
{
    e.Handled = true;
}

private void BorderManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
    // suppress zoom
    if (Math.Abs(e.DeltaManipulation.Scale.X) > 0.0||
        Math.Abs(e.DeltaManipulation.Scale.Y) > 0.0)
        e.Handled = true;
}

private void BorderManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
    // suppress zoom
    if (Math.Abs(e.FinalVelocities.ExpansionVelocity.X) > 0.0 ||
        Math.Abs(e.FinalVelocities.ExpansionVelocity.Y) > 0.0)
        e.Handled = true;
}



回答2:


On Mark's direction, I used

private void Border_ManipulationDelta(object sender,
                                              System.Windows.Input.ManipulationDeltaEventArgs e)
        {

            e.Complete();
            _browser.IsHitTestVisible = false;

        }


来源:https://stackoverflow.com/questions/16787331/windows-phone-avoid-scrolling-of-web-browser-control-placed-inside-scroll-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!