我尝试了以下方法,同时将父StackPanel(VisualContainer)和子StackPanel(Items)上的ManipulationMode作为ManipulationMode处理。但是我面临的问题是滚动不停止,而在拖动动作后通过触摸屏幕来停止滚动动作。我用下面的代码。
问题:在UWP中执行掠过动作后,触摸屏幕时滚动不会停止
对于子级StackPanel(项目)ManipulationMode作为系统,它工作正常。但不能在子级StackPanel(项)ManipulationMode中作为全部
使用注意:我必须将子堆栈面板(项)ManipulationMode设置为ALL。
在此附上示例代码段。
MainPage.xaml
<Page
x:Class="App4.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App4"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<ScrollViewer x:Name="ScrollViewer">
<!--It is a Parent Stack Panel - VisualContainer-->
<StackPanel Background="AntiqueWhite" x:Name="VisualContainer" HorizontalAlignment="Stretch">
<!--It is a Child Stack Panel, The below views are Items-->
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
<local:StackPanelExt Background="Aquamarine" Height="100" />
<local:StackPanelExt Background="Pink" Height="100" />
</StackPanel>
</ScrollViewer>
</Grid>
</Page>
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace App4
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
VisualContainer.ManipulationMode = ManipulationModes.All;
VisualContainer.ManipulationDelta += VisualContainer_ManipulationDelta;
}
private void VisualContainer_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
ScrollViewer.ChangeView(0, ScrollViewer.VerticalOffset - e.Delta.Translation.Y, null, true);
}
}
public class StackPanelExt : StackPanel
{
public StackPanelExt()
{
//this.ManipulationDelta += StackPanelExtExt_ManipulationDelta;
this.ManipulationMode = ManipulationModes.All;
}
private void StackPanelExtExt_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
{
var x = e.Cumulative.Translation.X;
var y = e.Cumulative.Translation.Y;
if (Math.Abs(y) <= Math.Abs(x))
{
e.Handled = true;
}
else
{
e.Handled = false;
}
}
}
}