【发布时间】:2019-12-15 17:23:01
【问题描述】:
我有处理 Id 和名称列表的 IListViewModel。 我还有 4 个其他 ViewModel 名为 AViewModel 、 BViewModel 、 CViewModel 、 DViewModel 和我在 Xamarin 项目中使用了 Prism 框架
每次我导航到另一个页面时,我都会在列表中添加新项目。
我所期望的是,在我导航到页面后,列表中将有 4 个项目,但不幸的是,
以下 sn-ps 是我在其中一个 ViewModel 上的示例代码
public class CPageViewModel : BaseViewModel
{
private readonly INavigationService _navigationService;
private readonly IListTestViewModel _listTestViewModel;
public ICommand NavigateToPreviousCommand => new DelegateCommand(async () => await NavigateToPrevious());
public ICommand NavigateToRootCommand => new DelegateCommand(async () => await NavigateToRoot());
public CPageViewModel(INavigationService navigationService, IListTestViewModel listTestViewModel) : base(navigationService)
{
this._navigationService = navigationService;
this._listTestViewModel = listTestViewModel;
listTestViewModel.TestListCollection.Add(new MyTestModel { Id = 4, Name = "Josh" });
}
private Task NavigateToPrevious()
{
return _navigationService.NavigateAsync("BPage");
}
private Task NavigateToRoot()
{
return _navigationService.GoBackToRootAsync();
}
}
我在列表中获得 1 条记录。下面是我遇到的问题的示例项目文件
【问题讨论】:
标签: c# mvvm xamarin.forms cross-platform prism