WP8浏览器作为全景/枢轴项目
本文关键字:项目 全景 浏览器 WP8 | 更新日期: 2023-09-27 18:12:21
我添加了一个WebBrowser作为其中一个全景项的内容。WebBrowser的渲染没有任何问题。如果我通过触摸WebBrowser外部的区域来滑动全景图,则会发生滑动。但是当我试图通过触摸WebBrowser来滑动全景图时,滑动不会发生,而是WebBrowser垂直滚动。知道怎么解决这个问题吗?
我没有反对,但可能是因为这是个坏主意。根据设计,这些项目不应该组合在一起。然而,如果你真的想让浏览器保持在枢轴内,你可以看一下这里
虽然你无疑会发现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。如果需要,或者为了更好地优化,请仅在选择包含浏览器的pivot项时订阅事件处理程序:
private void MyPivot_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if ((sender as Pivot).SelectedItem == BrowserPivotItem)
Touch.FrameReported += Touch_FrameReported;
else
Touch.FrameReported -= Touch_FrameReported;
}