標籤:style class code tar color width
1: TouchPoint mPoint = null;
2: double mOffsetX;//水平捲軸當前位置
3: double mOffsetY;//垂直捲軸當前位置
4: bool mIsTouch = false;//是否觸摸
5: //觸摸事件
6: private void mScrollViewer_TouchDown(object sender, TouchEventArgs e)
7: {
8: mIsTouch = true;//正在觸摸
9: mOffsetX = this.mScrollViewer.HorizontalOffset;//擷取ScrollViewer捲軸當前位置
10: mOffsetY = this.mScrollViewer.VerticalOffset;//擷取ScrollViewer捲軸當前位置
11: mPoint = e.GetTouchPoint(mScrollViewer);//擷取相對於ScrollViewer的觸摸點位置
12: }
13:
14: //觸摸移動事件
15: private void mScrollViewer_TouchMove(object sender, TouchEventArgs e)
16: {
17: if (mIsTouch == true)//如果正在觸摸
18: {
19: TouchPoint point = e.GetTouchPoint(mScrollViewer);//擷取相對於ScrollViewer的觸摸點位置
20: double DiffOffsetX = point.Position.X - mPoint.Position.X;//計算相對位置
21: double DiffOffsetY = point.Position.Y - mPoint.Position.Y;//計算相對位置
22: this.mScrollViewer.ScrollToHorizontalOffset(mOffsetX - DiffOffsetX);//ScrollViewer滾動到指定位置
23: this.mScrollViewer.ScrollToVerticalOffset(mOffsetY - DiffOffsetY);//ScrollViewer滾動到指定位置
24: }
25: }
26:
27: //觸摸結束事件
28: private void mScrollViewer_TouchUp(object sender, TouchEventArgs e)
29: {
30: mIsTouch = false;//觸摸結束
31: }