【问题标题】:Detect when Xamarin Scrollview has reached the end检测 Xamarin Scrollview 何时到达末尾
【发布时间】:2018-07-16 20:27:17
【问题描述】:

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

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

            }
        }

问题是即使页面只滚动到底部一次,这个函数也会被多次调用。有关如何处理此问题的任何提示?

【问题讨论】:

    标签: c# xamarin xamarin.forms


    【解决方案1】:

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

     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
            }
    

    【讨论】:

    • 值得注意的是,有时最好输入一个值 1 以防止计算错误。
    猜你喜欢
    • 1970-01-01
    • 2019-12-06
    • 1970-01-01
    • 1970-01-01
    • 2021-04-19
    • 1970-01-01
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多