我已经看到,自最新更新(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 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;
}
Output(PC端和手机端均可使用)
也归功于@贾斯汀XL https://stackoverflow.com/questions/45550684/horizontal-swipe-gesture-on-uwp答案,这是示例存储库 https://github.com/shubdragon/SwipeGestureRepoUWP
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)