处理向上滑动,向下滑动,向左滑动&在WinRT应用程序中滑动右手势

时间:2012-09-28 22:46:41

标签: c# .net xaml windows-runtime windows-store

我有以下代码:

public MainPage()
{
    this.InitializeComponent();
    this.ManipulationStarting += MainPage_ManipulationStarting;
    this.ManipulationStarted += MainPage_ManipulationStarted;
    this.ManipulationInertiaStarting += MainPage_ManipulationInertiaStarting;
    this.ManipulationDelta += MainPage_ManipulationDelta;
    this.ManipulationCompleted += MainPage_ManipulationCompleted;
}
void MainPage_ManipulationStarting(object sender, ManipulationStartingRoutedEventArgs e)
{
    Debug.WriteLine("MainPage_ManipulationStarting");
}
void MainPage_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
    Debug.WriteLine("MainPage_ManipulationStarted");
}
void MainPage_ManipulationInertiaStarting(object sender, ManipulationInertiaStartingRoutedEventArgs e)
{
    Debug.WriteLine("MainPage_ManipulationInertiaStarting");
}
void MainPage_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    Debug.WriteLine("MainPage_ManipulationDelta");
}
void MainPage_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
    Debug.WriteLine("MainPage_ManipulationCompleted");
}

但我不知道如何使用Manipulation事件。你能描述一下如何处理向上,向下,向左和向右滑动的手势吗?

3 个答案:

答案 0 :(得分:22)

操纵事件为您提供翻译值。操纵Delta将持续射击,直到您的操作与惯性一起完成。在这种情况下,检查移动是否是惯性的(正常移动不应被视为滑动)并检测初始位置和当前位置之间的差异。

达到阈值后,触发向上/向下/向左/向右滑动事件。并立即停止操纵,以避免一次又一次地发射相同的事件。

以下代码可以帮助您,

    private Point initialpoint;

    private void Grid_ManipulationStarted_1(object sender, ManipulationStartedRoutedEventArgs e)
    {
        initialpoint = e.Position;
    }

    private void Grid_ManipulationDelta_1(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        if (e.IsInertial)
        {
            Point currentpoint = e.Position;
            if (currentpoint.X - initialpoint.X >= 500)//500 is the threshold value, where you want to trigger the swipe right event
            {
                System.Diagnostics.Debug.WriteLine("Swipe Right");
                e.Complete();
            }
        }
    }

答案 1 :(得分:4)

我尝试了XAML爱人的答案,但对我来说并不准确(IsIntertial总是对我不利)。对于想要尝试不同的人,我实现了一些不同的东西(我在此回复了之前相关主题的帖子Handling Swipe Guesture in Windows 8 Grid)。

答案 2 :(得分:2)

看一下GestureRecognizer .CrossSliding事件。 还有EdgeGesture类和样本:EdgeGesture samplegestures sample