在我的Xamarin应用程序中添加新记录时出现问题



我在项目中使用Freshsmvvm,我想显示一个操作列表,

这是我从crud中得到的方法

public List<Operation> GetAll()
{
try
{
return connection.Table<Operation>().ToList();
}
catch (Exception ex)
{
StatusMessage = $"Error: {ex.Message}";
}
return null;
}

在我的视图模型中,我有一个列表和获取保存记录的方法

private List<Operation> _listOp;
public List<Operation> ListOp
{
get { return _listOp; }
set
{
_listOp = value;
RaisePropertyChanged();
}
}
private void GetOp()
{
ListOp = App.OperationRepository.GetAll();
}

*add the GetOp method in the constructor to load in the collectionview*
public override void Init(object initData)
{
GetOp();
}

结果是列表没有更新,我不得不关闭应用程序,当我再次打开它时,输入的记录就会出现。

这是没有添加新记录的列表

这是重新启动应用后的日志列表

您可以使用方法OnAppearing((来刷新列表。

protected override async void OnAppearing()
{
base.OnAppearing();
ListOp = App.OperationRepository.GetAll();
}

最新更新