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

时间:2014-09-10 11:16:32

标签: c# windows-phone windows-phone-8.1 swipe

我正在尝试在以下应用中实现水平滑动事件处理程序。但是,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
    }
}

1 个答案:

答案 0 :(得分:0)

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

在这种情况下,我正在使用Grid(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.
}