Windows phone - Avoid scrolling of Web browser con

2019-05-20 23:00发布

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.

2条回答
The star\"
2楼-- · 2019-05-20 23:24

On Mark's direction, I used

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

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

        }
查看更多
地球回转人心会变
3楼-- · 2019-05-20 23:36

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;
}
查看更多
登录 后发表回答