如何在Windows Phone 8.1中处理水平滑动事件

本文关键字:水平 处理 平滑 事件 Windows Phone | 更新日期: 2023-09-27 18:21:16

我正试图在下面的应用程序中实现一个水平滑动事件处理程序。但是,gr_CrossSliding交叉滑动事件处理程序从不启动。

我需要做什么才能激发gr_CrossSliding

public sealed partial class MainPage : Page
{
    private GestureRecognizer gr;
    public MainPage()
    {
        this.InitializeComponent();
        gr = new GestureRecognizer();
        gr.GestureSettings = GestureSettings.CrossSlide;
        gr.CrossSlideHorizontally = true;
        gr.CrossSliding += gr_CrossSliding;
    }
    void gr_CrossSliding(GestureRecognizer sender, CrossSlidingEventArgs args)
    {
        // handle swipe event
    }
}

如何在Windows Phone 8.1中处理水平滑动事件

您需要在获取手势的UI元素的处理程序上设置手势识别器。

在这种情况下,我使用的是一个网格(GrdFoto)。

public MainPage()
{
    this.InitializeComponent();
    gestureRecognizer.GestureSettings = Windows.UI.Input.GestureSettings.Drag;
    gestureRecognizer.Dragging += gestureRecognizer_Dragging;
    GrdFoto.PointerPressed += GrdFoto_PointerPressed;
    GrdFoto.PointerMoved += GrdFoto_PointerMoved;
    GrdFoto.PointerReleased += GrdFoto_PointerReleased;
    GrdFoto.PointerCanceled += GrdFoto_PointerCanceled;
}

void GrdFoto_PointerPressed(object sender, PointerRoutedEventArgs e)
{
    this.gestureRecognizer.ProcessDownEvent(e.GetCurrentPoint(this.GrdFoto));
    this.GrdFoto.CapturePointer(e.Pointer);
    e.Handled = true;
}
void GrdFoto_PointerMoved(object sender, PointerRoutedEventArgs e)
{
    this.gestureRecognizer.ProcessMoveEvents(e.GetIntermediatePoints(this.GrdFoto));
}
void GrdFoto_PointerReleased(object sender, PointerRoutedEventArgs e)
{
    this.gestureRecognizer.ProcessUpEvent(e.GetCurrentPoint(this.GrdFoto));   
    e.Handled = true;
}
void GrdFoto_PointerCanceled(object sender, PointerRoutedEventArgs e)
{
    this.gestureRecognizer.CompleteGesture();
    e.Handled = true;
}
void gestureRecognizer_Dragging(GestureRecognizer sender, DraggingEventArgs args)
{
    // Drag completed.
}