2

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.

pg90
  • 423
  • 2
  • 6
  • 16

2 Answers2

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;
}
Mark Monster
  • 397
  • 3
  • 10
  • Thanks Mark. Yes your answer showed right direction. As private void Border_ManipulationDelta(object sender, System.Windows.Input.ManipulationDeltaEventArgs e) { e.Complete(); _browser.IsHitTestVisible = false; } – pg90 Jun 05 '13 at 10:50
  • Is BorderDoubleTap getting fired? – vITs Aug 13 '14 at 07:29
1

On Mark's direction, I used

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

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

        }
pg90
  • 423
  • 2
  • 6
  • 16