我和你们在同一条船上,因为没有关于这是如何完成的示例,但是在仔细阅读并仔细检查了 MSDN 文档关于如何使用 C# 在 Windows 8 商店应用程序上实现滑动手势之后,这就是我想出的(它适用于我需要向上/向下/向左/向右滑动的应用程序):
首先,需要使用 Manipulation 事件而不是 GestureRecognizer,因此在您要处理滑动的网格上(假设您将其设置为占用整个屏幕,以便解释手势) 执行以下操作:
我调用了我的网格 swipingSurface,我正在处理 Y 轴和 X 轴的操作模式:
swipingSurface.ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY;
然后连接您想要通知的操作事件,在我的情况下,我只想知道操作开始以及何时结束:
swipingSurface.ManipulationStarted += OnManipulationStarted;
swipingSurface.ManipulationCompleted += OnManipulationCompleted;
在你的操作开始时做任何你想做的事情,比如如果你想得到初始点。但实际的技巧在于 ManipulationCompleted 事件,您需要在该事件中获取手势产生的速度,如下所示:
public void OnManipulationCompleted(object sender, ManipulationCompletedEventArgs e) {
var velocities = e.Velocities;
}
ManipulationCompletedEventArgs Velocity 属性将返回一个 ManipulationVelocities 类型的结构,其中包含其他属性:
-角度:以度/毫秒为单位的旋转速度。
-扩展:扩展或缩放速度,以每毫秒 DIP 为单位。
-线性:以每毫秒 DIP 为单位的直线速度。
我实际上是在看Linear速度,它是一个Point,其中包含表示手势执行方向的X和Y值;例如,如果向上滑动,您会注意到 Y 值为正,如果向下滑动,则 Y 值为负; X 值也是如此,如果向左滑动,则 X 值为负,如果向右滑动,则 X 值为正,因此您可以使用这些值并检查您的滑动方向、最终点等.
希望这会有所帮助。