[英]WP8 WebBrowser as Panorama/Pivot Item
我添加了一個WebBrowser作為全景項目之一的內容。 WebBrowser呈現沒有問題。 如果我通過觸摸Web瀏覽器外部的區域來滑動全景,則會發生滑動。 但是,當我嘗試通過觸摸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.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.