c# - 如何在列表视图内容页面 Xamarin 上自动刷新数据
问题描述
我在列表视图中添加数据,但我需要先关闭程序才能显示数据。我应该添加什么来自动刷新内容页面。
班级
public class Cart : BindableObject
{
public string product_id { get; set; }
public string name { get; set; }
public string price { get; set; }
public string image { get; set; }
public string quantity { get; set; }
}
解决方案
如果ViewModel使用ObservableCollection创建Cart列表,则 ListView 将在运行时添加数据时更新。
例如:
public ObservableCollection<Cart > CartItems { set; get; }
CartItems.Add(new Cart(){...})
推荐阅读
- c# - 如何使用asp.net在当前html中显示另一个html?
- c++ - Boost 进程在新窗口中打开进程 (Windows)
- flutter - 创建一个观看列表的流?
- c# - 将一个类的多个属性聚合成一个字符串
- reactjs - 为什么我的 iframe 有时会在签署 DocuSign 表单之前首先加载返回 URL 页面?
- c# - 从我的方法中替换 IF 和 Else If 语句
- git - 使用 husky hook 强制推送到另一个远程分支
- c++ - 现代 CMake - 带有 set_property 或 target_compile_features 的 C++ 版本
- file - 电子自定义拖动图标
- haskell - 为什么 ghc (Haskell) 编译器找不到我导入的模块 Data.Vector?我收到错误:找不到模块“Data.Vector”