GroupViewPage页面布局
<?xml version="1.0" encoding="utf-8" ?> <ContentPage x:Class="XFInfiniteScroll.Views.GroupViewPage" xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:extended="clr-namespace:Xamarin.Forms.Extended;assembly=Xamarin.Forms.Extended.InfiniteScrolling"> <ContentPage.Content> <ListView x:Name="GroupItems" HasUnevenRows="True" HorizontalOptions="FillAndExpand" IsGroupingEnabled="True" VerticalOptions="FillAndExpand"> <ListView.Behaviors> <extended:InfiniteScrollBehavior IsLoadingMore="{Binding IsWorking}" /> </ListView.Behaviors> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <Grid Padding="12"> <Grid.ColumnDefinitions> <ColumnDefinition> </ColumnDefinition> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition> </RowDefinition> <RowDefinition> </RowDefinition> </Grid.RowDefinitions> <Label Grid.Row="0" Text="{Binding Text}" TextColor="Black"> </Label> <Label Grid.Row="1" Text="{Binding Description}" TextColor="Black"> </Label> </Grid> </ViewCell> </DataTemplate> </ListView.ItemTemplate> <ListView.GroupHeaderTemplate> <DataTemplate> <ViewCell> <Grid BackgroundColor="White"> <Label FontAttributes="None" FontSize="16" HorizontalTextAlignment="Center" Text="{Binding Header}" TextColor="Blue" VerticalTextAlignment="Center"> </Label> </Grid> </ViewCell> </DataTemplate> </ListView.GroupHeaderTemplate> <ListView.Footer> <Grid Padding="6"> <Label HorizontalOptions="Center" IsVisible="{Binding IsWorking}" Text="Load..." TextColor="Black" VerticalOptions="Center"> </Label> </Grid> </ListView.Footer> </ListView> </ContentPage.Content> </ContentPage>对于后台代码,可以在GitHub上面参考。https://github.com/mzy666888/XFInfiniteScroll
第八步现在,可以运行你的Xamarin.Forms应用程序,并可以看到以下的输出内容。
在本机上运行界面:
视频地址:https://www.zhihu.com/zvideo/1338425998501240832
看一下原文中的动图显示
iOS Android原文地址https://xmonkeys360.com/2021/01/04/xamarin-forms-infinite-scroll-listview-lazy-loading/