问题描述
我在列表视图中添加数据,但我需要先关闭程序才能显示数据。我应该添加什么来自动刷新内容页面。
课程
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(){...})