我正在使用 xamarin 表单在滚动视图中显示项目列表。我想添加一个功能,以便当用户滚动到页面底部时我可以触发一个事件(例如加载更多项目)。目前,我正在使用此 OnScrolled 函数来触发加载事件:
private void OnScrolled()
{
if (Scroller.ScrollY >= (Scroller.ContentSize.Height -Scroller.Height)+1)
{
//load more items
}
}
Run Code Online (Sandbox Code Playgroud)
问题是,即使页面只滚动到底部一次,该函数也会被多次调用。关于如何处理这个问题有什么建议吗?
该方法将被多次调用,因为您正在使用滚动更改的事件处理程序。
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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3747 次 |
| 最近记录: |