我怎样才能在 Xamarin 中创建无限滚动

How can I creat endless scrolling in Xamarin

所以我有这个应用程序,我试图在其中创建循环滚动,例如,在向下滚动时我得到:

... - 项目 4 - 项目 5 - 项目 1 - 项目 2 - 项目 3 - 项目 4 - 项目 5 - 项目 1 - 项目 2 - 项目 3 - ...

这是我正在尝试的图片

所以滚动将是无止境的,因为相同的项目将被重复。谁能帮我解决这个问题?

可以参考Infinite Scrolling

这是一个简单的示例:

安装 Nuget Xamarin.Forms.Extended.InfiniteScrolling

页面的 axml :

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:scroll="clr-namespace:Xamarin.Forms.Extended;assembly=Xamarin.Forms.Extended.InfiniteScrolling"
         x:Class="InfiniteScrollingApp.SimplePage">

    <!-- a normal list view -->
    <ListView  CachingStrategy="RecycleElement" ItemsSource="{Binding Items}">

        <!-- the behavior that will enable infinite scrolling -->
        <ListView.Behaviors>
            <scroll:InfiniteScrollBehavior />
        </ListView.Behaviors>

        <!-- the row definition -->
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                        <Label Text="{Binding Name}" />
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>


    </ListView>

视图模型:

public class MyViewModel
{
    public InfiniteScrollCollection<MyData> Items { get; set; }

    public MyViewModel()
    {

        var items = new InfiniteScrollCollection<MyData>();
        MyData data1 = new MyData() { Name = "1" };
        MyData data2 = new MyData() { Name = "2" };
        MyData data3 = new MyData() { Name = "3" };
        MyData data4 = new MyData() { Name = "4" };
        MyData data5 = new MyData() { Name = "5" };
        MyData data6 = new MyData() { Name = "6" };
        MyData data7 = new MyData() { Name = "7" };
        MyData data8 = new MyData() { Name = "8" };
        MyData data9 = new MyData() { Name = "9" };
        MyData data10 = new MyData() { Name = "10" };
        MyData data11 = new MyData() { Name = "11" };
        MyData data12 = new MyData() { Name = "12" };
        items.Add(data1);
        items.Add(data2);
        items.Add(data3);
        items.Add(data4);
        items.Add(data5);
        items.Add(data6);
        items.Add(data7);
        items.Add(data8);
        items.Add(data9);
        items.Add(data10);
        items.Add(data11);

        items.Add(data12);
        Items = items;
        //var dataSource = new MyDataSource();

        Items = new InfiniteScrollCollection<MyData>
        {
            OnLoadMore = async () =>
            {

                return items;
            }
        };
        // load the initial data
        Items.LoadMoreAsync();
    }
}

模特:

public class MyData
{
    public string Name { set; get; }
}

效果如下: