检测滚动已通过PointerWheelChanged完成 [英] Detect scroll is completed with PointerWheelChanged

查看:127
本文介绍了检测滚动已通过PointerWheelChanged完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用WinRT上的PointerWheelChanged事件检测鼠标滚轮滚动.我使用PointerPoint.Properties.MouseWheelDelta来检测滚动的数量和方向:

I detect mouse wheel scroll using PointerWheelChanged event at WinRT. I use PointerPoint.Properties.MouseWheelDelta to detect amount and direction of scroll:

PointerPoint mousePosition = e.GetCurrentPoint(_control);
var delta = mousePosition.Properties.MouseWheelDelta;

如今,有些设备可以模拟鼠标滚动(触摸板或触摸鼠标等). 他们往往会为每个滚动"发出数十个或数百个(sic!)PointerWheelChanged事件.旧鼠标滚轮每点击一次鼠标就会发出一个事件,其增量为+ -120个单位.

Nowadays there are devices which emulate mouse scroll (touchpad or touch mice etc). They tend to issue tens or hundreds (sic!) PointerWheelChanged events per "scroll". Legacy mouse wheel issues one event per wheel click which has delta of +-120 units.

用户滚动到某个位置时,我需要做一些繁重的处理.

I need to do some heavy processing as soon as user scrolls to some position.

有没有办法理解新"滚动是否完成?

Is there a way to understand that "new" scroll is complete?

仅供参考,这是使用Microsoft TouchMouse进行单指轻击的鼠标滚轮增量(抱歉,我只想举例说明问题).

FYI Here is a mouse wheel deltas for a single finger flick with Microsoft TouchMouse (sorry for the amount, I just want to illustrate the problem).

15 15 164 164 304 304 658 658 773 773 887 887 1000 1000 1111 1111 1221 1221 1330 1330 108 108 107 107 106 106 105 105 104 104 103 103 102 102 203 203 100 100 99 99 98 98 97 97 96 96 95 95 94 94 93 93 92 92 91 91 90 90 89 89 88 88 88 88 87 87 86 86 85 85 84 84 83 83 82 82 82 82 81 81 80 80 79 79 78 78 78 78 77 77 76 76 75 75 75 75 74 74 73 73 72 72 72 72 71 71 70 70 70 70 69 69 68 68 67 67 67 67 66 66 65岁 65岁 65岁 65岁 64 64 63 63 63 63 62 62 62 62 61 61 60 60 60 60 59 59 59 59 58 58 57 57 57 57 56 56 56 56 55 55 55 55 54 54 54 54 53 53 52 52 52 52 51 51 51 51 50 50 50 50 49 49 49 49 48 48 48 48 47 47 47 47 46 46 46 46 46 46 45 45 45 45 44 44 44 44 43 43 43 43 42 42 42 42 42 42 41 41 41 41 40 40 40 40 40 40 39 39 39 39 38 38 38 38 38 38 37 37 37 37 37 37 36 36 36 36 35 35 35 35 35 35 34 34 34 34 34 34 33 33 33 33 33 33 32 32 32 32 32 32 31 31 31 31 31 31 30 30 30 30 30 30 30 30 29 29 29 29 29 29 28岁 28岁 28岁 28岁 28岁 28岁 28岁 28岁 27 27 27 27 27 27 26 26 26 26 26 26 26 26 25 25 25 25 25 25 25 25 24 24 24 24 24 24 24 24 23 23 23 23 23 23 23 23 23 23 22 22 22 22 22 22 22 22 21岁 21岁 21岁 21岁 21岁 21岁 21岁 21岁 21岁 21岁 20 20 20 20 20 20 20 20 20 20 19 19 19 19 19 19 19 19 19 19 18岁 18岁 18岁 18岁 18岁 18岁 18岁 18岁 18岁 18岁 18岁 18岁 17 17 17 17 17 17 17 17 17 17 17 17 16 16 16 16 16 16 16 16 16 16 16 16 15 15 15 15 15 15 15 15 15 15 15 15 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 13 13 13 13 13 13 13 13 13 13 13 13 13 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 15 15 22 22 7 7 7 7 14 14 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 8 8 12 12 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 9 9 3 3 3 3 3 3 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 2个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1个 1

15 15 164 164 304 304 658 658 773 773 887 887 1000 1000 1111 1111 1221 1221 1330 1330 108 108 107 107 106 106 105 105 104 104 103 103 102 102 203 203 100 100 99 99 98 98 97 97 96 96 95 95 94 94 93 93 92 92 91 91 90 90 89 89 88 88 88 88 87 87 86 86 85 85 84 84 83 83 82 82 82 82 81 81 80 80 79 79 78 78 78 78 77 77 76 76 75 75 75 75 74 74 73 73 72 72 72 72 71 71 70 70 70 70 69 69 68 68 67 67 67 67 66 66 65 65 65 65 64 64 63 63 63 63 62 62 62 62 61 61 60 60 60 60 59 59 59 59 58 58 57 57 57 57 56 56 56 56 55 55 55 55 54 54 54 54 53 53 52 52 52 52 51 51 51 51 50 50 50 50 49 49 49 49 48 48 48 48 47 47 47 47 46 46 46 46 46 46 45 45 45 45 44 44 44 44 43 43 43 43 42 42 42 42 42 42 41 41 41 41 40 40 40 40 40 40 39 39 39 39 38 38 38 38 38 38 37 37 37 37 37 37 36 36 36 36 35 35 35 35 35 35 34 34 34 34 34 34 33 33 33 33 33 33 32 32 32 32 32 32 31 31 31 31 31 31 30 30 30 30 30 30 30 30 29 29 29 29 29 29 28 28 28 28 28 28 28 28 27 27 27 27 27 27 26 26 26 26 26 26 26 26 25 25 25 25 25 25 25 25 24 24 24 24 24 24 24 24 23 23 23 23 23 23 23 23 23 23 22 22 22 22 22 22 22 22 21 21 21 21 21 21 21 21 21 21 20 20 20 20 20 20 20 20 20 20 19 19 19 19 19 19 19 19 19 19 18 18 18 18 18 18 18 18 18 18 18 18 17 17 17 17 17 17 17 17 17 17 17 17 16 16 16 16 16 16 16 16 16 16 16 16 15 15 15 15 15 15 15 15 15 15 15 15 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 13 13 13 13 13 13 13 13 13 13 13 13 13 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 15 15 22 22 7 7 7 7 14 14 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 8 8 12 12 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 9 9 3 3 3 3 3 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

现在,我要进行此破解,但这远非完美

Now I do this hack but it is far from perfect

// interval between mouse deltas
private readonly TimeSpan _wheelDeltaThrottleInterval = TimeSpan.FromMilliseconds(8);

// interval to wait until scroll is complete
private readonly TimeSpan _wheelDeltaCompleteInterval = TimeSpan.FromMilliseconds(600);

// create smart wheel handler
IObservable<PointerPoint> pointerWheelObservable = 
    System.Reactive.Linq.Observable
        .FromEventPattern<PointerEventHandler, PointerRoutedEventArgs>(
            handler => _control.PointerWheelChanged += handler,
            handler => _control.PointerWheelChanged -= handler)
        .Select(eventPattern =>
            {
                PointerRoutedEventArgs e = eventPattern.EventArgs;
                PointerPoint mousePosition = e.GetCurrentPoint(_control);
                return mousePosition;
            })
        .Where(mousePosition => Math.Abs(mousePosition.Properties.MouseWheelDelta) > MouseWheelDeltaThreshold);

// subscribe to wheel changes
pointerWheelObservable
    .Throttle(_wheelDeltaThrottleInterval)
    .ObserveOnDispatcher()
    .Subscribe(
        OnPointerWheelChanged,
        Logger.TrackException);

pointerWheelObservable
    .Throttle(_wheelDeltaCompleteInterval)
    .Subscribe(
        OnPointerWheelCompleted,
        Logger.TrackException);


EDIT2 GestureRecognizer类没有帮助


EDIT2 GestureRecognizer class does not help

请参阅此精彩的博客文章,了解有关Windws 8操作处理的信息. http://blogs .msdn.com/b/windowsappdev/archive/2012/07/02/modernizing-input-in-windows-8.aspx

See this great blog post regarding Windws 8 manipulations handling. http://blogs.msdn.com/b/windowsappdev/archive/2012/07/02/modernizing-input-in-windows-8.aspx

不幸的是,经过我的实验,我发现GestureRecognizer无法检测到洪水结束的鼠标滚轮事件.每次调用.ProcessMouseWheelEvent()后,都会触发ManipulationCompleted事件.

Unfortunately after my experiments I see GestureRecognizer is not able to detect mouse wheel events flood is over. It fires ManipulationCompleted event after each call of .ProcessMouseWheelEvent()

推荐答案

使用GestureRecognizer可以更好地检测包括鼠标鸣叫在内的各种操作. 所有输入(鼠标,触摸,笔等)都包含在此处,并且比传统的操作事件提供更好的支持. (它们不支持单点触摸旋转,鼠标滚动等).

Use GestureRecognizer for a better low level detection of manipulations including mouse whell. All inputs (mouse, touch, pen, etc.) are included here and supported better than traditional manipulation events. (they don't support single touch rotation, mouse scroller, etc.)

http://code.msdn.microsoft. com/windowsapps/Input-Windows-8-gestures-62c6689b#content

这比从头开始执行所有操作要高效,灵活和安全.

This is much more efficient, flexible and safer than implementing everything from scratch.

这篇关于检测滚动已通过PointerWheelChanged完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆