dra*_*lic 2 c# gesture visual-studio swipe uwp
我已经看到,自最新更新(Windows Fall Creators Update)以来,存在一组 Swipe Classes,但在 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>
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
输出 (适用于 PC 和移动设备)也归功于@JustinXL答案,这是示例存储库