Xamarin.Forms Carousel Page Swipe Event Page Changing

喜欢而已 提交于 2019-12-13 05:35:53

问题


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.

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?

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


回答1:


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];

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.

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.



来源:https://stackoverflow.com/questions/48425853/xamarin-forms-carousel-page-swipe-event-page-changing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!