如何使用滑动动画以编程方式在 FlipView 中导航 [英] How to programmatically navigate in a FlipView with swipe animations

查看:18
本文介绍了如何使用滑动动画以编程方式在 FlipView 中导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows 开发人员中心对 UseTouchAnimationsForAllNavigation 属性的说明:

The Windows Dev Center states regarding the UseTouchAnimationsForAllNavigation property:

XAML FlipView 控件支持三种导航模式;基于触摸、基于按钮和程序化.当用户通过触摸导航时,FlipView 项目会平滑地滚动到视图中.当您将此属性设置为 true 时,无论导航是基于触摸的、基于按钮的还是程序化的,都会发生相同的导航动画.

The XAML FlipView control supports three modes of navigation; touch-based, button-based and programmatic. When a user navigates by touch, the FlipView items scroll smoothly into view. When you set this property to true, the same navigation animation occurs whether the navigation is touch-based, button-based and programmatic.

我目前正在通过分配 FlipView 的 SelectedItem 属性从我的页面代码后面导航:

I'm currently navigating from my page's code behind by assigning the SelectedItem property of the FlipView:

FlipView.SelectedItem = FlipView.Items.Last();

但是,滑动动画不显示.如何启用它?

However, the swipe animation does not show. How can I enable it?

推荐答案

与此同时,我能够解决这个问题.我有一个按钮可以触发导航到下一个 FlipViewItem.然而,这个按钮被放置在一个 FlipViewItem 中.

Meanwhile, I was able to solve this problem. I have a button that triggers the navigation to the next FlipViewItem. This button however was placed in a FlipViewItem.

使用我的设置(触摸设备),没有任何反应.然后我尝试用鼠标单击按钮,它起作用了.在我禁用 UseTouchAnimationsForAllNavigation 后,它也可以使用触摸输入.在我的测试中,我将按钮放置在 FlipView 之外,它确实使用了动画.

With my setup (touch device), nothing happend. Then I tried clicking the button with the mouse and it worked. After I disabled UseTouchAnimationsForAllNavigation, it also worked using touch input. In my tests, I placed the button outside of the FlipView and it did work using animations.

问题在于:当点击按钮时,导航动画尝试启动(SelectedIndex 设置正确),但由于用户仍然触摸按钮阻止动画而停止.因此,导航被取消并且 SelectionChanged 报告当前页面.

Here's the problem: When tapping the button, the navigation animation tries to start (SelectedIndex is set correctly), but stopped because the user blocks the animation by still touching the button. So, the navigation is cancelled and SelectionChanged reports the current page.

解决办法是将Button的ManipulationMode设置为All.之后,您无法在触摸按钮时翻转 FlipViewItem,但动画会执行并且效果很好.

The solution is to set ManipulationMode of the Button to All. After that, you can't flip the FlipViewItem when touching the button, but the animation executes and it works like charm.

这篇关于如何使用滑动动画以编程方式在 FlipView 中导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆