WP8 WebBrowser作为Panorama / Pivot项目

时间:2013-05-07 10:12:19

标签: c# windows-phone-7 windows-phone-8 windows-phone-7.1 windows-phone-7.1.1

我添加了一个WebBrowser作为其中一个全景项的内容。 WebBrowser呈现没有问题。如果我通过触摸WebBrowser外部的区域来滑动全景图,则会发生滑动。但是当我尝试通过触摸WebBrowser来扫描全景图时,滑动不会发生,而是WebBrowser垂直滚动。知道如何解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

我没有投票,但可能,因为这是一个坏主意。按设计,这些项目不应合并。但是,如果您确实希望将浏览器保持在枢轴内,则可以一目了然here

答案 1 :(得分:0)

虽然您无疑会发现这不是UI指南推荐的,但这是我的必要条件,我可以通过直接订阅Touch事件并手动检测滑动来解决这个问题:

    // controls "swipe" behavior
    private Point touchDownPosition;  // last position of touch down
    private int touchDownTime;        // last time of touch down
    private int touchUpTime;          // last time of touch up
    private int swipeMaxTime = 1000;  // time (in milliseconds) that a swipe must occur in
    private int swipeMinDistance = 25;// distance (in pixels) that a swipe must cover
    private int swipeMinBounceTime = 500; // time (in milliseconds) between multiple touch events (minimizes "bounce")

    // handler for touch events
    void Touch_FrameReported(object sender, TouchFrameEventArgs e) 
    {
        var item = MyPivot.SelectedItem as PivotItem;

        // ignore touch if we are not on the browser pivot item
        if (item != BrowserPivotItem) 
            return;

        var point = e.GetPrimaryTouchPoint(item);
        switch (point.Action) 
        {
            case TouchAction.Down:
                touchDownTime = e.Timestamp;
                touchDownPosition = point.Position;
                touchUpTime = 0;
                break;

            case TouchAction.Up:
                // often multiple touch up events are fired, ignore re-fired events
                if (touchUpTime != 0 && touchUpTime - e.Timestamp < swipeMinBounceTime)
                    return;

                touchUpTime = e.Timestamp;
                var xDelta = point.Position.X - touchDownPosition.X;
                var yDelta = point.Position.Y - touchDownPosition.Y;
                // ensure touch event meets the requirements for a "swipe"
                if (touchUpTime - touchDownTime < swipeMaxTime && Math.Abs(xDelta) > swipeMinDistance && Math.Abs(xDelta) > Math.Abs(yDelta)) 
                {
                    // advance to next pivot item depending on swipe direction
                    var iNext = MyPivot.SelectedIndex + (delta > 0 ? -1 : 1);
                    iNext = iNext < 0 || iNext == MyPivot.Items.Count ? 0 : iNext;
                    MyPivot.SelectedIndex = iNext;
                }
                break;
        }
    }

然后订阅所需的Touch.FrameReported,或者为了更好的优化,仅在选择包含浏览器的数据透视表项时订阅事件处理程序:

    private void MyPivot_OnSelectionChanged(object sender, SelectionChangedEventArgs e) 
    {
        if ((sender as Pivot).SelectedItem == BrowserPivotItem) 
          Touch.FrameReported += Touch_FrameReported;
        else 
          Touch.FrameReported -= Touch_FrameReported;
    }