简体   繁体   English

WP8 WebBrowser作为全景图/透视图项

[英]WP8 WebBrowser as Panorama/Pivot Item

I added a WebBrowser as the content of one of the panorama items. 我添加了一个WebBrowser作为全景项目之一的内容。 The WebBrowser gets rendered with no issues. WebBrowser呈现没有问题。 If I swipe the panorama by touching the area outside the WebBrowser the swipe happens. 如果我通过触摸Web浏览器外部的区域来滑动全景,则会发生滑动。 But when I try to swipe the panorama by touching the WebBrowser, the swipe does not happen, instead the WebBrowser scrolls vertically. 但是,当我尝试通过触摸WebBrowser滑动全景时,不会发生滑动,而是WebBrowser垂直滚动。 Any idea how this can be fixed ? 知道如何解决这个问题?

I didn't downvote, but probably, because its a bad idea. 我没有投票,但是可能是因为这是一个坏主意。 By design, those items should not be combined. 通过设计,这些项目不应合并。 However, if you really want to keep browser inside pivot, you can take a glance here 但是,如果您真的想让浏览器始终处于旋转状态,则可以在此处浏览一下

While you'll undoubtedly come to find that this is not recommended by the UI guidelines, this was a necessary requirement in my case and I was able to work around this by subscribing directly to the Touch events and manually detecting a swipe: 尽管您无疑会发现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;
        }
    }

Then subscribe to the Touch.FrameReported where desired, or for better optimization, subscribe to the event handler only while the pivot item containing the browser is selected: 然后,在需要的地方订阅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;
    }


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM