检测Xamarin Scrollview何时结束 [英] Detect when Xamarin Scrollview has reached the end

查看:78
本文介绍了检测Xamarin Scrollview何时结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用xamarin表单在滚动视图中显示项目列表.我想添加一个功能,以便当用户滚动到页面底部时,我可以触发一个事件(例如,加载更多项目).当前,我正在使用此OnScrolled函数触发加载事件:

I am using xamarin forms to display a list of items in a scrollview. I would like to add a feature so that when the user scrolls to the bottom of the page I can trigger an event (ex. load more items). Currently, I am using this OnScrolled Function to trigger the loading event:

private void OnScrolled()
        {
            if (Scroller.ScrollY >= (Scroller.ContentSize.Height -Scroller.Height)+1)
            {
               //load more items

            }
        }

问题在于,即使页面仅滚动到底部一次,该函数也会被多次调用.有关如何处理此问题的任何提示?

The problem is that this function gets called multiple times even though the page has only been scrolled to the bottom once. Any tips on how to deal with this?

推荐答案

该方法将被多次调用,因为您正在使用事件处理程序来更改滚动.

The method will be called multiple times, because your are using an event handler for the scroll changed.

 private void OnScrolled(object sender, ScrolledEventArgs e)
        {
            MyScrollView scrollView = sender as MyScrollView;
            double scrollingSpace = scrollView.ContentSize.Height - scrollView.Height;

            if (scrollingSpace <= e.ScrollY) // Touched bottom
                // Do the things you want to do
        }

这篇关于检测Xamarin Scrollview何时结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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