c# - Xamarin 表单集合视图分页
问题描述
我想以 xamarin 形式实现分页,实际上我还没有为任何移动应用程序这样做,所以这是我的第一次。我正在使用集合视图和剩余项目阈值,并且正在触发事件,但未添加项目。我认为这是一个很好的逻辑,但我认为我错过了一些东西。提前致谢!
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);
}
解决方案
因此,感谢@Jason,看来项目源(在我的情况下为 ordersToShow)必须是可观察的集合而不是列表
推荐阅读
- c# - 为什么我对 RichTextBox.AppendText() 的 C# 代码调用没有一致地处理 \r\n?
- javascript - 变量未在 .then 处理程序中定义
- reactjs - 如何将 Material UI 中的 BOX 组件用于不同的屏幕尺寸?
- node.js - 在 openapi-generator-cli nodejs-express-server 后面编写 Node 业务逻辑
- javascript - 使用 React,单击后退按钮时,视图正在正确更新,但 URL 未正确更新
- reactjs - 错误:在使用 fetch 从 api 收集数据时,对象作为 React 子项(找到:[object Promise])在反应中无效
- javascript - TypeError 提供的 fullPermissions 不是带有斜杠命令权限的 GuildApplicationCommandPermissionData 数组(v13 Discord.js)
- reactjs - React 在我们的页面上获取 iframe 播放视频的图像并将其保存到本地驱动器的最佳方法是什么?
- python - 无法为 Python 3.9 64 位运行 PythonWin
- android - Flutter Google Maps - 将相机移动到当前位置