首页 > 解决方案 > 如何在列表视图内容页面 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; } 
} 

标签: c#xamarinxamarin.forms

解决方案


如果ViewModel使用ObservableCollection创建Cart列表,则 ListView 将在运行时添加数据时更新。

例如:

public ObservableCollection<Cart > CartItems { set; get; }

CartItems.Add(new Cart(){...})

推荐阅读