C# 横向滑动不';我不能在超宽带工作
我正在努力在我的UWP应用程序中启用水平滑动/轻弹。我已经按照MSDN链接添加了C# 横向滑动不';我不能在超宽带工作,c#,windows-10,uwp,windows-10-mobile,windows-10-universal,C#,Windows 10,Uwp,Windows 10 Mobile,Windows 10 Universal,我正在努力在我的UWP应用程序中启用水平滑动/轻弹。我已经按照MSDN链接添加了手势识别器。如果我的XAML页面中只有Grid和TextBlock控件,那么它工作得很好。但是,在我的XAML页面中有Grid和ListBox。它不适用于列表框 这是一个样本 类GestureInputProcessor { Windows.UI.Input.GestureRecognitor GestureRecognitor; 元素 public GestureInputProcessor(Win
手势识别器
。如果我的XAML页面中只有Grid
和TextBlock
控件,那么它工作得很好。但是,在我的XAML页面中有Grid
和ListBox
。它不适用于列表框
这是一个样本
类GestureInputProcessor
{
Windows.UI.Input.GestureRecognitor GestureRecognitor;
元素
public GestureInputProcessor(Windows.UI.Input.GestureRecognizer gr, Windows.UI.Xaml.UIElement target)
{
gestureRecognizer = gr;
element = target;
gestureRecognizer.GestureSettings =
Windows.UI.Input.GestureSettings.Tap |
Windows.UI.Input.GestureSettings.Hold | Windows.UI.Input.GestureSettings.RightTap |
Windows.UI.Input.GestureSettings.CrossSlide;
// Set up pointer event handlers. These receive input events that are used by the gesture recognizer.
element.PointerCanceled += OnPointerCanceled;
element.PointerPressed += OnPointerPressed;
element.PointerReleased += OnPointerReleased;
element.PointerMoved += OnPointerMoved;
// Set up event handlers to respond to gesture recognizer output
Windows.UI.Input.CrossSlideThresholds threshold = new Windows.UI.Input.CrossSlideThresholds();
threshold.SelectionStart = 2;
threshold.SpeedBumpStart = 3;
threshold.SpeedBumpEnd = 4;
threshold.RearrangeStart = 5;
gestureRecognizer.CrossSlideHorizontally = true;
gestureRecognizer.CrossSlideThresholds = threshold;
gestureRecognizer.CrossSliding += GestureRecognizer_CrossSliding;
}
private void GestureRecognizer_CrossSliding(Windows.UI.Input.GestureRecognizer sender, Windows.UI.Input.CrossSlidingEventArgs args)
{
MessageService.showMessage("You are here", MessageType.Information);
}
void OnPointerPressed(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs args)
{
// Route teh events to the gesture recognizer
gestureRecognizer.ProcessDownEvent(args.GetCurrentPoint(element));
// Set the pointer capture to the element being interacted with
element.CapturePointer(args.Pointer);
// Mark the event handled to prevent execution of default handlers
args.Handled = true;
}
void OnPointerCanceled(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs args)
{
gestureRecognizer.CompleteGesture();
args.Handled = true;
}
void OnPointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs args)
{
gestureRecognizer.ProcessUpEvent(args.GetCurrentPoint(element));
args.Handled = true;
}
void OnPointerMoved(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs args)
{
gestureRecognizer.ProcessMoveEvents(args.GetIntermediatePoints(element));
}
}
XAML页面
<Grid x:Name="LayoutRoot" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="1">
<ListBox x:Name="lsbReadingChapter" ItemsSource="{Binding ChapterContent}" SelectedItem="{Binding SelectedAya}" DoubleTapped="lsbReadingChapter_DoubleTapped"
FlowDirection="RightToLeft" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Visibility="{Binding Visiblity}" HorizontalAlignment="Stretch" FlowDirection="{Binding TranslationLanguage.FlowDirection}" FontSize="{Binding TranslationFont.FontSize}" TextWrapping="Wrap" FontFamily="{Binding TranslationFont.FontPath}" Text="{Binding AyaTranslation}">
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
指针事件也会在ListBox
中触发,但手势不起作用。我希望在ListBox
控件中启用向左/向右滑动。是否可能
谢谢!在我看来,这个手势可能会首先被
列表框的滚动视图捕获,所以不能与列表框一起工作,我们将继续寻找解决这个问题的方法。首先,我认为列表框是一个旧控件,为了获得最佳体验,你应该使用列表视图。其次,你能使用Pivo吗这是用来刷标签的平台控件。谢谢,@GraceFeng MSFT我希望在这个问题上有一个UWP解决方案。同样的问题可以在WP8 Silverlight中使用Microsoft Phone Toolkit解决。Quincy我想看看我是否可以使用ListView,但是,很抱歉我不能在我的情况下使用Pivot。@ARH你呢想要这样的吗?
//Handle horizental / vertical swipe event
GestureRecognizer gr1 = GestureRecognizer();
public MainPage()
{
//swipe event this works well, If I have TextBlock instead of ListBox
GestureInputProcessor ShapeInput1 = new GestureInputProcessor(gr1, LayoutRoot);
}