WPF Image触摸移动方法
时间:2014-05-04 12:05:12
收藏:0
阅读:1023
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: }
评论(0)