2

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

4

2 回答 2

0

我没有投反对票,但可能是因为这是个坏主意。按照设计,这些项目不应组合在一起。但是,如果您真的想将浏览器保留在枢轴中,您可以看一眼这里

于 2013-05-07T11:51:17.833 回答
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;
    }


于 2013-10-17T19:53:19.723 回答