在 UWP 中使用滑动手势

Use Swipe Gesture in UWP

我看到自从最新更新(Windows Fall Creators Update)以来,存在一个 Swipe 类 集合,但在当前稳定版本的 VS ( 15.4.1 ) 中有不是让它工作的方法。我目前 运行 使用 Visual Studio 2017 Enterprise ( 15.4.1 ) 的最新 W10 更新 (1709),但无法使其正常工作。我试图让下面的例子工作但没有成功:https://channel9.msdn.com/Events/Windows/Windows-Developer-Day-Fall-Creators-Update/WinDev015#comments

我正在 TextBlock 上应用轻扫,您可以在您的控件上应用。

XAML

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Name="SwipeableTextBlock" 
               HorizontalAlignment="Stretch"
               VerticalAlignment="Stretch"
               TextAlignment="Center" Text="No Swipe"
               FontSize="65" FontWeight="Light"
               ManipulationMode="TranslateX,TranslateInertia,System" 
               ManipulationDelta="SwipeableTextBlock_ManipulationDelta"
               ManipulationCompleted="SwipeableTextBlock_ManipulationCompleted"/>
</Grid>

C#

private bool _isSwiped;

private void SwipeableTextBlock_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
    if (e.IsInertial && !_isSwiped)
    {
        var swipedDistance = e.Cumulative.Translation.X;

        if (Math.Abs(swipedDistance) <= 2) return;

        if (swipedDistance > 0)
        {
            SwipeableTextBlock.Text = "Right Swiped";
        }
        else
        {
            SwipeableTextBlock.Text = "Left Swiped";
        }
        _isSwiped = true;
    }            
}

    private void SwipeableTextBlock_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
    {
        _isSwiped = false;
    }     

输出 (适用于 PC 和移动设备) 也归功于 answer and this is sample repository