女师傅一体2,数据库关系模型,间客5200
listbox支持触摸滑动,而scrollviewer默认不支持。
scrollviewer如需要添加上下/左右触摸移动,需要在touch事件中处理。
处理如下:封装成一个用户控件
注:scrollviewer滚动到指定位置(指定位置=起始位置-移动的偏移量,滚动方向和手势方向相反)
1 /// <summary> 2 /// 可触摸滚动的scrollviewer控件 3 /// </summary> 4 public class touchablescrollviewer : scrollviewer 5 { 6 //触摸点的坐标 7 point _startposition; 8 //滚动条当前位置 9 double _startverticaloffset; 10 double _starthorizontaloffset; 11 public touchablescrollviewer() 12 { 13 touchdown += touchablescrollviewer_touchdown; 14 15 touchup += touchablescrollviewer_touchup; 16 } 17 private void touchablescrollviewer_touchdown(object sender, toucheventargs e) 18 { 19 //添加触摸移动监听 20 touchmove -= touchablescrollviewer_touchmove; 21 touchmove += touchablescrollviewer_touchmove; 22 23 //获取scrollviewer滚动条当前位置 24 _startverticaloffset = verticaloffset; 25 _starthorizontaloffset = horizontaloffset; 26 27 //获取相对于scrollviewer的触摸点位置 28 touchpoint point = e.gettouchpoint(this); 29 _startposition = point.position; 30 } 31 32 private void touchablescrollviewer_touchup(object sender, toucheventargs e) 33 { 34 //注销触摸移动监听 35 touchmove -= touchablescrollviewer_touchmove; 36 } 37 38 private void touchablescrollviewer_touchmove(object sender, toucheventargs e) 39 { 40 //获取相对于scrollviewer的触摸点位置 41 touchpoint endpoint = e.gettouchpoint(this); 42 //计算相对位置 43 double diffoffsety = endpoint.position.y - _startposition.y; 44 double diffoffsetx = endpoint.position.x - _startposition.x; 45 46 //scrollviewer滚动到指定位置(指定位置=起始位置-移动的偏移量,滚动方向和手势方向相反) 47 scrolltoverticaloffset(_startverticaloffset - diffoffsety); 48 scrolltohorizontaloffset(_starthorizontaloffset - diffoffsetx); 49 } 50 }
demo下载
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论