我试图为横向设置滑动控制,使用下面的代码我可以帮助以横向方式工作。
TouchPoint _first;
private List<TList> _pivotList;
public Pivot()
{
InitializeComponent();
Loaded += pivot_Loaded;
Touch.FrameReported += Touch_FrameReported;
}
private void Touch_FrameReported(object sender,TouchFrameEventArgs e)
{ TouchPoint mainTouch = e.GetPrimaryTouchPoint(null);
if (mainTouch.Action == TouchAction.Down)
_first = mainTouch;
else if (mainTouch.Action == TouchAction.Up)
{
var xDelta = mainTouch.Position.X - _first.Position.X;
var yDelta = Math.Abs(mainTouch.Position.Y - _first.Position.Y);
if (yDelta > Math.Abs(xDelta))
return;
if (Math.Abs(xDelta - 0) > 10)
{
var currentIndex = pivotList.SelectedIndex;
int noOfPivotItems = pivotList.Items.Count;
currentIndex = (xDelta < 0) ?
++currentIndex % noOfPivotItems :
(--currentIndex + noOfPivotItems) % noOfPivotItems;
pivotList.SelectedIndex = currentIndex;
}
}
}