Xamarin.Forms轮播页面滑动事件页面更改 [英] Xamarin.Forms Carousel Page Swipe Event Page Changing

查看:525
本文介绍了Xamarin.Forms轮播页面滑动事件页面更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xamarin Form(2.5.0)附带的轮播"页面,希望能够检测页面何时将要更改.

I'm using the Carousel Page that ships with Xamarin Form (2.5.0) and would like to be able to detect when a page is about to change.

每个页面都有一些验证,如果验证失败,我想防止用户移动到下一页.目前,我只能看到的唯一事件是PageChanged,这是我触发验证的地方,但是用户必须向后滑动才能看到错误消息.

Each Page has some validation and if this fails I want to prevent the user from moving to the next page. Currently the only event I can see is PageChanged and this is where I trigger the validation, however the user must swipe back to see the error message.

有没有办法钩住本机滑动事件?

Is there a way to hook into the native swipe event?

该应用当前针对iOS,但最终将需要支持Android.

The App is currently targeting iOS, however it will eventually need to support Android.

推荐答案

我知道有些晚了,但是也许其他人也可能会问,所以这里有个主意: 如您所写,在

I know it's a bit late, but maybe someone else might also ask, so here's an idea: As you wrote, in

protected override void OnCurrentPageChanged()    

您可以了解用户何时滑动到下一页.现在,如果您对上一页进行验证,则在出现错误的情况下可以返回上一页

you could find out when a user swiped to the next page. Now if you do the validation for the previous page, you could go back to the previous page in case of error with

int index = Children.IndexOf(CurrentPage);
this.CurrentPage = this.Children[index-1];

这不会阻止用户离开页面(因为没有"OnSwipingStart"或其他内容),但是用户将看到错误而不必手动返回.

This does not prevent the user from leaving the page (as there is no 'OnSwipingStart' or else), but the user will see the error without having to move back manually.

如果您愿意使用与CarouselPage不同的控件,请执行以下操作: 有一个拉请求以获取

If you are happy to use a different control than CarouselPage: There is a pull request to get CarouselView into native Xamarin Forms. It has a Scrolled-Event which is triggered already on the first percent swiped so you could do your actions there.

这篇关于Xamarin.Forms轮播页面滑动事件页面更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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