我已经看到,自从最新更新(Windows Fall Creators Update)以来,存在一组滑动类,但在当前稳定版本的 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 和移动设备) 也归功于@JustinXL回答,这是样本 repository
关于c# - 在 UWP 中使用滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46962632/