gpt4 book ai didi

c# - 如何在 Windows 10 UWP 中为网格添加触摸操作事件?

转载 作者:行者123 更新时间:2023-11-30 15:21:44 25 4
gpt4 key购买 nike

我目前在 Windows 10 上工作,我想为用户添加滑动手势。所以我做了一些研究,发现了操纵事件。我尝试了以下代码,但它在我使用鼠标指针时有效,而不是在使用触摸滑动手势时有效。

 pageLayoutGrid.ManipulationMode = ManipulationModes.TranslateX;
pageLayoutGrid.ManipulationDelta += PageLayoutGrid_ManipulationDelta;
pageLayoutGrid.ManipulationCompleted += LayoutManipulationCompleted;

private void PageLayoutGrid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
e.Handled = true;
}

private void LayoutManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
var velocities = e.Velocities.Linear;
Double swipeLeftRight = velocities.X;
Double swipeUpDown = velocities.Y;
// A negative value means swiping to the left
if (swipeLeftRight < 0)
{
navigateToNextPage();
}
// a positive value is a swipe to the right.
else if (swipeLeftRight > 0)
{
navigateToPreviousPage();
}
}

这个 Grid 的子元素是 ScrollViewer。

有人可以建议代码有什么问题吗?

最佳答案

作为对 link 的引用这是解决方案

我正在 ScrollViewerPointerEntered 事件中禁用 ScrollViewer VerticalScrollMode 以便调用 Grid Manipulation 事件.启用 VerticalScrollMode 一旦操作完成,即在 ManipulationCompleted 事件中

ScrollViewer scroolviewr;
private void ScrollViewer_PointerEntered(object sender, PointerRoutedEventArgs e)
{
scroolviewr = (sender as ScrollViewer);
(sender as ScrollViewer).VerticalScrollMode = ScrollMode.Disabled;
}
private void PageLayoutGrid_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
e.Handled = true;
}

private void LayoutManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
scroolviewr.VerticalScrollMode = ScrollMode.Enabled;
var velocities = e.Velocities.Linear;
Double swipeLeftRight = velocities.X;
Double swipeUpDown = velocities.Y;
// A negative value means swiping to the left
if (swipeLeftRight < 0)
{
navigateToNextPage();
}
// a positive value is a swipe to the right.
else if (swipeLeftRight > 0)
{
navigateToPreviousPage();
}
}




<Grid ManipulationMode="TranslateX" ManipulationDelta="Grid_ManipulationDelta" ManipulationCompleted="Grid_ManipulationCompleted">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" HorizontalScrollMode="Disabled" PointerEntered="ScrollViewer_PointerEntered">
.....
</ScrollViewer>

</Grid>

关于c# - 如何在 Windows 10 UWP 中为网格添加触摸操作事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36912034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com