原文:2019-11-29-WPF-开启-ScrollViewer-的触摸滚动

title author date CreateTime categories
WPF 开启 ScrollViewer 的触摸滚动
lindexi
2019-11-29 10:21:47 +0800
2018-12-26 11:51:31 +0800
WPF

在 ScrollViewer 如果需要收到触摸消息,通过 Manipulation 触摸滚动,不能只是通过设置 IsManipulationEnabled 方法,还需要设置 PanningMode 才可以

那么如何知道滚动条的触摸事件是否触发,可以写一个类继承滚动条

    public class StisvearpaHudalserevow : ScrollViewer
{
/// <inheritdoc />
protected override void OnManipulationDelta(ManipulationDeltaEventArgs e)
{
Debug.WriteLine("OnManipulationDelta");
base.OnManipulationDelta(e);
} /// <inheritdoc />
protected override void OnManipulationCompleted(ManipulationCompletedEventArgs e)
{
Debug.WriteLine("OnManipulationCompleted");
base.OnManipulationCompleted(e);
} /// <inheritdoc />
protected override void OnManipulationStarted(ManipulationStartedEventArgs e)
{
Debug.WriteLine("OnManipulationStarted");
base.OnManipulationStarted(e);
}
}

在界面添加这个类,如果有触摸输入就可以通过输出看到了,简单一个界面,可以看到默认的滚动条是不能滚动的

同时触摸的时候没有输出

尝试添加 IsManipulationEnabled 方法

<local:StisvearpaHudalserevow IsManipulationEnabled="True">

可以看到有输出但是就是不能滚动

在我博客 WPF 拖动滚动 告诉大家通过 PanningMode 的方法可以让滚动条滚动

只要在初始的过程设置了 PanningMode 因为在代码里面通过 InvalidateProperty 重新设置 IsManipulationEnabled 的值,所以只需要设置 PanningMode 就可以

       /// <summary>
/// Method which sets IsManipulationEnabled
/// property based on the PanningMode
/// </summary>
private void OnPanningModeChanged()
{
PanningMode mode = PanningMode; // Call InvalidateProperty for IsManipulationEnabledProperty
// to reset previous SetCurrentValueInternal if any.
// Then call SetCurrentValueInternal to
// set the value of these properties if needed.
InvalidateProperty(IsManipulationEnabledProperty); if (mode != PanningMode.None)
{
SetCurrentValueInternal(IsManipulationEnabledProperty, BooleanBoxes.TrueBox);
}
}

但是如果在触摸的过程,出现了设置 IsManipulationEnabled 为 false 就会触发 OnManipulationCompleted 事件

        protected override void OnManipulationStarted(ManipulationStartedEventArgs e)
{
Debug.WriteLine("OnManipulationStarted");
base.OnManipulationStarted(e); Task.Delay(TimeSpan.FromSeconds(3)).ContinueWith(_ => IsManipulationEnabled = false,
TaskScheduler.FromCurrentSynchronizationContext());
}

还可以通过设置 IsHitTestVisible = false 触发 OnManipulationCompleted 同时触发之后也没有触摸

2019-11-29-WPF-开启-ScrollViewer-的触摸滚动的更多相关文章

  1. 2019.11.29 Mysql的数据操作

    为名为name的表增加数据(插入所有字段) insert into name values(1,‘张三’,‘男’,20); 为名为name的表增加数据(插入部分字段) insert into name ...

  2. 2019.11.29 SAP SMTP郵件服務器配置 發送端 QQ郵箱

    今天群裏的小夥伴問了如何配置郵件的問題,隨自己在sap裏面配置了一個 1.    RZ10配置參數 a)       参数配置前,先导入激活版本 执行完毕后返回 b)      输入参数文件DEFAU ...

  3. pycharm+anaconda在Mac上的配置方法 2019.11.29

    内心os: 听人说,写blog是加分项,那他就不是浪费时间的事儿了呗 毕竟自己菜还是留下来东西来自己欣赏吧 Mac小电脑上进行python数据开发环境的配置 首先下载Anaconda,一个超好用的数据 ...

  4. Supervision meeting notes 2019/11/29

    topic 分支:  1. subgraph/subsequence mining Wang Jin, routine behavior/ motif. Philippe Fournier Viger ...

  5. WPF的ScrollViewer鼠标的滚动

    在C# 中,两个ScrollViewer嵌套在一起或者ScrollViewer里面嵌套一个ListBox.Listview(控件本身有scrollviewer)的时候,我们本想要的效果是鼠标滚动整个S ...

  6. WPF中ScrollViewer嵌套引发滚动失灵的Bug

    事情起因 测试报告说存在滚动条不能拖动的情况,我们几个开发人员多次测试都未重现该问题.后面发现是操作系统的问题,在XP和部分Win7上会存在该问题.而在我们开发人员的机器上,包括Win7 SP1,Wi ...

  7. 解决WPF的ScrollViewer在使用触摸屏时,滑到尽头窗口抖动的情况

    原文:解决WPF的ScrollViewer在使用触摸屏时,滑到尽头窗口抖动的情况 wpf的ScrollViewer在触摸条件下 默认在尽头时会有一个窗口一起被拖动的FeedBack,但对用户的交互很不 ...

  8. EOJ Monthly 2019.11 E. 数学题(莫比乌斯反演+杜教筛+拉格朗日插值)

    传送门 题意: 统计\(k\)元组个数\((a_1,a_2,\cdots,a_n),1\leq a_i\leq n\)使得\(gcd(a_1,a_2,\cdots,a_k,n)=1\). 定义\(f( ...

  9. 通过解读 WPF 触摸源码,分析 WPF 插拔设备触摸失效的问题(问题篇)

    在 .NET Framework 4.7 以前,WPF 程序的触摸处理是基于操作系统组件但又自成一套的,这其实也为其各种各样的触摸失效问题埋下了伏笔.再加上它出现得比较早,触摸失效问题也变得更加难以解 ...

随机推荐

  1. 电信NBIOT 5 - NB73模块下行测试(自己平台-电线平台-NB73)

    电信NBIOT 1 - 数据上行(中国电信开发者平台对接流程) 电信NBIOT 2 - 数据上行(中间件获取电信消息通知) 电信NBIOT 3 - 数据下行 电信NBIOT 4 - NB73模块上行测 ...

  2. 汇编指令之STOS、REP

    版权声明:本文为博主原创文章,转载请附上原文出处链接和本声明.23:28:13,23:28:19作者By-----溺心与沉浮----博客园 STOS指令:讲Al/AX/EAX的值存储到[EDI]指定的 ...

  3. Spring Cloud Netflix之Eureka Clients服务提供者

    之前一章我们介绍了如何搭建Eureka Server,这一章,我们介绍如何搭建服务提供者. Eureka Clients介绍 服务的提供者,通过发送REST请求,将自己注册到注册中心(在高可用注册中心 ...

  4. 机器学习(4)——PCA与梯度上升法

    主成分分析(Principal Component Analysis) 一个非监督的机器学习算法 主要用于数据的降维 通过降维,可以发现更便于人类理解的特征 其他应用:可视化.去噪 通过映射,我们可以 ...

  5. 201871010125-王玉江《面向对象程序设计(java)》第十五周学习总结

    项目 内容 这个作业属于哪个课程 <任课教师博客主页链接> https://www.cnblogs.com/nwnu-daizh/ 这个作业的要求在哪里 <作业链接地址> ht ...

  6. arm指令集图片

  7. Linux学习笔记-第8天 - 看似很简单

    这些东西已经看了三遍,已经能够理解了.看似很简单,希望真正在用的时候不会出差子.

  8. luoguP4551最长异或路径

    P4551最长异或路径 链接 luogu 思路 从\(1\)开始\(dfs\)求出\(xor\)路径.然后根据性质\(x\)到\(y\)的\(xor\)路径就是\(xo[x]^xo[y]\) 代码 # ...

  9. cf1182D Complete Mirror

    可以得到一个结论, 可行的点要么是直径端点, 要么是直径中点, 要么是直径中点引出的链中最短的端点 #include<cstdio> #include<algorithm> # ...

  10. CSP2019许愿贴

    CSP2019RP++