如何在Xamarin Forms中的滚动视图中检测击中网格底部 [英] How to detect hitting the bottom of a grid within a scrollview in Xamarin Forms
问题描述
我正在使用Xamarin.Forms在GridView(在ScrollView中)中显示来自Websource的项目.
I am using Xamarin.Forms to display Items from a Websource in a Grid (within a ScrollView).
当用户点击网格底部时,我想加载更多项目并将其添加到网格中.我知道通常使用ListView首选以这种方式显示数据(并且ListView具有ItemAppearing事件),但可悲的是,我必须使用网格.
When the user hits the bottom of the grid, i want to load more items and add them to the grid. I know that usually a ListView is preferred for displaying data in this fashion (and that ListView has an ItemAppearing event) but sadly i have to use a grid.
如果有帮助,我可以发布一些代码,但不确定在这里是否有必要.
If it helps, i could post some code, but im not sure if that is necessary here.
先谢谢了 这是我非常无聊的布局文件:
Thanks in advance here is my really boring layout file:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyProject.MyNamespace.LayoutName"
SizeChanged="OnPageSizeChanged">
<ScrollView >
<AbsoluteLayout x:Name="myLayout">
<Grid x:Name="GridForItems" RowSpacing="6" ColumnSpacing="6">
</Grid>
</AbsoluteLayout>
</ScrollView>
</ContentPage>
我以编程方式添加所有行,列和项目.
I add all the rows, columns and items programmatically.
推荐答案
由于我对原问题(如何检测滚动视图的底部的底部)没有令人满意的答案,所以我有了在网络上其他任何地方都找不到解决方案,我将发布解决方法.
Since i had not gotten a satisfying answer to my original question (how to detect hitting the bottom of a scrollview) and i have not found a solution anywhere else on the net i am going to post how i solved this.
请注意,这可能不是一个很好的解决方案,如果您有更好的答案,请张贴它,我会接受它作为最佳答案.
Note that this is probably the not an elegant solution and, if you have a better answer, please post it and i will accept it as the best answer.
我所做的是实现ScrollView的Scrolled Event的委托.
What i did was implement a delegate for the Scrolled Event of ScrollView.
myScrollView.Scrolled += (sender, e) => { onScrolled(); };
在onScrolled中,我有以下if子句来确定我是否触及了ScrollView的底部:
Within my onScrolled i have the following if-clause to determine whether i have hit the bottom of the ScrollView:
private void onScrolled()
{
if(myScrollView.ScrollY >= myScrollView.ContentSize.Height - myScrollView.Height)
{
//Handle hitting the bottom
}
}
这篇关于如何在Xamarin Forms中的滚动视图中检测击中网格底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!