使用 GestureRecognizer 处理 PointerWheelChanged 事件

Process PointerWheelChanged event with GestureRecognizer

我有一个 UWP 应用程序,我想在其中处理 ManipulationDeltaManipulationUpdatedManipulationCompletedPointerWheelChanged 事件(以处理鼠标或触摸板的水平滚动) .

PointerwheelChanged 事件中,我用

解决了这个问题
gesture.ProcessMouseWheelEvent(e.GetCurrentPoint(this), false,false);

其中 ePointerRoutedEventArgs

代码片段:

GestureRecognizer gesture = new GestureRecognizer();
gesture.ManipulationCompleted += OnManipulationCompleted;
gesture.ManipulationUpdated += OnManipulationUpdated;

 void OnManipulationUpdated(object sender, ManipulationUpdatedEventArgs e)
{
 //Ideally this Should be called whenever there is a change in manipulation
}

void OnManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
    {
    //Code for Scroll
//Ideally this has to be called on completion of Manipulation Event(Correct me if am wrong)
    }


 private void onPointerwheelChanged(object sender, PointerRoutedEventArgs e)
{
 gesture.ProcessMouseWheelEvent(e.GetIntermediatePoints((this) sender)[0], false, false);
}

此方法的问题是,无论何时触发 onPointerwheelChanged 事件,ManipulationCompleted 都会触发太多,尽管我在 TouchPad 中执行了一次长滑动(手指在整个滑动过程中都与触摸板接触)。

理想情况下,单张长幻灯片结束时应只触发一个 ManipulationCompleted 事件。但是触发了多个 ManipulationCompleted 事件。

有办法解决这个问题吗? 使 GestureRecognizer 仅在幻灯片结束时触发 ManipulationCompleted 事件?

whenever onPointerwheelChanged event is fired , ManipulationCompleted is too fired

这是预期的行为。根据 PointerWheelChanged event:

If the element where pointer events occur has a non-default ManipulationMode value, then the action might also result in various manipulation events like ManipulationStarted.

此行为的原因已解释here

The mouse wheel button has discrete, evenly spaced notches or distance thresholds (also called detents). When you rotate or tilt the wheel, a wheel message is sent as each detent is encountered.

所以,如果你想在用户完成旋转鼠标滚轮时处理一些事情。我建议您遵循以下选项之一:

  1. 如果你想显示事件的一些数据(例如网格的位置)。每次触发 ManipulationCompleted 事件时更新它。因此,用户将看到实时数据。

  2. 您可以为边界点设置状态(例如bool gridHitBoundary=false)。在OnManipulationUpdated中当边界点被击中时更新状态,在ManipulationCompleted中当gridHitBoundary==true时更新运行逻辑。