0
我最近开始使用MvvmCross 5并使用新的INavigationService。使用MvvmCross打开对话框片段时创建ViewModel的多个实例
不过,我一直无法找到呈现对话片段,我还是用我的旧方法在自定义演示(MvxFragmentsPresenter)的任何新的方法如下:
protected override void ShowFragment(MvxViewModelRequest request)
{
var currentActivity = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity;
var appActivity = currentActivity as MvvmCross.Droid.FullFragging.Views.MvxActivity;
if (appActivity != null)
{
var loaderService = Mvx.Resolve<IMvxViewModelLoader>();
var viewModel = loaderService.LoadViewModel(request, null);
if (request.ViewModelType == typeof(ExampleViewModel))
{
var dialogFragment = new ExampleDialogFragment();
dialogFragment.ViewModel = (ExampleViewModel)viewModel;
dialogFragment.SetStyle(DialogFragmentStyle.Normal, Resource.Style.MainDialogTheme);
dialogFragment.Show(appActivity.FragmentManager, ExampleDialogFragment.DialogTag);
return;
}
}
我的问题当我需要将参数传递给此对话框片段时,导航服务会创建具有正确参数的视图模型,但当它显示片段时,自定义演示者将构造一个不带任何参数的新视图模型,并将其设置为新的对话框片段。
我已经尝试使用MvxDefaultViewModelLocator而不是加载程序,但这只是做同样的事情。
var locatorService = Mvx.Resolve<IMvxViewModelLocator>();
var viewModel = locatorService.Load(request.ViewModelType, new MvxBundle(request.ParameterValues), null);
是否有一种新的方法来打开对话框片段,以便使用参数创建的视图模型可以分配给它?
感谢您的指点。