• 触摸屏实现触摸垂直滑动效果


     <ScrollViewer x:Name="scrollViewer" Grid.Row="1" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Visible">
                <TextBlock xml:space="preserve" Grid.Row="1" Width="820" x:Name="TBContent" Style="{StaticResource ContentTextBlock}" TouchDown="TBContent_TouchDown" TouchMove="TBContent_TouchMove"/>
            </ScrollViewer>

    前端用一个ScrollViewer 加文本 使用TouchDown 和 touchMove事件

    后台事件代码:

     double downYPosition = 0; //记录当前触摸位置
            private void TBContent_TouchDown(object sender, System.Windows.Input.TouchEventArgs e)
            {
                var position = e.GetTouchPoint(this);
                downYPosition= position.Position.Y;
            }
    
            private void TBContent_TouchMove(object sender, System.Windows.Input.TouchEventArgs e)
            {
                var position = e.GetTouchPoint(this);
                var y = position.Position.Y;
                var disY = y - downYPosition;
    
                var offset = scrollViewer.VerticalOffset;
                var curOffset = offset - disY;
    
                if (curOffset <= 0)
                {
                    curOffset = 0;
                }
                else if(curOffset> scrollViewer.ExtentHeight)
                {
                    curOffset = scrollViewer.ExtentHeight;
                }
    
                scrollViewer.ScrollToVerticalOffset(curOffset);
    
                downYPosition = y;
            }
  • 相关阅读:
    SQL SERVER没有足够的内存继续执行程序 (MSCORLIB)的解决办法
    Python之数据分析
    python之爬虫
    Linux从入门到放弃(为做一个开发+运维的全能性人才而奋斗)
    从零开始学python
    VUE学习
    Python进阶
    MySQL系列
    python基础其他
    Microsoft Office 2010/2013安装组件预设
  • 原文地址:https://www.cnblogs.com/guiqiang/p/10411501.html
Copyright © 2020-2023  润新知