首页 > 解决方案 > 将记录设置为在 Xamarin 表单中一次显示 10 条记录的列表视图

问题描述

我正在研究 Xamarin 表单。

我有 200 条记录要显示在 listview 上,但我只想加载 10 条记录来显示。当我滚动列表视图时,应该显示接下来的 10 条记录。

有什么解决办法吗?

标签: xamarin.forms

解决方案


使用您定义的下一个和上一个按钮使用自定义分页。使用 LINQ 获取/跳过每 10 条记录。使用 Label 保存计数并将其 IsVisible 属性设置为 false。

public List<Product> List(int page =1, string category =null)
{
    if (category != null) this.CurrentCategory = category;

    var products = repository.Products
                   .Where(p => this.CurrentCategory == null || p.Category == this.CurrentCategory)
                   .OrderBy(p => p.ProductID)
                   .Skip((page -1) * PageSize)
                   .Take(PageSize);

var count = repository.Products
                   .Where(p => this.CurrentCategory == null || p.Category == this.CurrentCategory).Count();

var resultAsPagedList = products.ToList();

    return resultAsPagedList;
}

如果您需要更多信息,请告诉我。


推荐阅读