【问题标题】:Xamarin Forms Collection View PaginationXamarin 表单集合视图分页
【发布时间】:2021-07-07 22:23:06
【问题描述】:

我想在 xamarin 表单中实现分页,实际上我还没有为任何移动应用程序这样做,所以这是我的第一次。我正在使用 collection viewremainingItemThreshold 并且正在触发事件,但未添加项目。我认为这是一个很好的逻辑,但我认为我遗漏了一些东西。提前致谢!

        private async void Init()
    {
        SetViews();

        Methods.SetFlowDirection(this);

        Methods.BeforeChecking(activityIndicator, parent);

        GetOrdersApiResponse response = await OrdersPageLogic.GetOrders();

        Methods.AfterChecking(activityIndicator, parent);
        //
        // get all orders
        orders = response.Orders;
        
        toRange = orders.Count >= pagination ? pagination : orders.Count;

        // only show first 10 items
        ordersToShow = orders.GetRange(0, toRange);

        // remove fetched items
        orders.RemoveRange(0, toRange);

        ordersCollView.ItemsSource = ordersToShow;
        
        ordersCollView.RemainingItemsThreshold = 2;

        ordersCollView.RemainingItemsThresholdReached += (s, e) => ordersCollView_RemainingItemsThresholdReached(s, e);
    }

    private void ordersCollView_RemainingItemsThresholdReached(object s, EventArgs e)
    {
        int count = 0;
        int to = 0;

        if (orders.Count == 0)
            return;

        to = pagination >= orders.Count ? orders.Count : pagination;

        foreach(var order in orders.GetRange(0, to))
        {
            if (count == pagination)
                break;

            ordersToShow.Add(order);
            count++;
        }

        // remove fetched items
        orders.RemoveRange(0, to);
    }

【问题讨论】:

  • ordersToShow 还是ObservableCollection?
  • @Jason DAMN 我忘了它必须是,我将它定义为一个列表。我会试一试,但是是的,我认为它会起作用,我会回复你
  • @Jason 总能拯救我的一天!谢谢你

标签: c# xamarin xamarin.forms mobile uicollectionview


【解决方案1】:

感谢@Jason,看来项目来源(在我的例子中是 ordersToShow)必须是 observable collection 而不是 list

【讨论】:

    猜你喜欢
    • 2020-06-29
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 2020-04-12
    • 1970-01-01
    • 1970-01-01
    • 2019-10-15
    • 1970-01-01
    相关资源
    最近更新 更多