下载最新版本的 mvvmcross (V3) 后,我有一些工作要做,将我的一些项目升级到新的状态。我无法完成的最后一件事是将参数从 tabhost 传递给 viewmodel。在旧版本中它工作正常(但它不同),现在我得到了一个错误。
但首先这里的代码(第 19 行有问题(在代码中查看注释),第 18 行有效,但只有没有参数):
[Activity]
public class MainActivity : MvxTabActivity
{
public new MainViewModel ViewModel
{
get { return (MainViewModel)base.ViewModel; }
set { base.ViewModel = value; }
}
protected override void OnViewModelSet()
{
SetContentView(Resource.Layout.Main);
TabHost.TabSpec spec;
Intent intent;
spec = TabHost.NewTabSpec("listeaktiv");
spec.SetIndicator(App.indicatorActive, Resources.GetDrawable(Resource.Drawable.green));
//spec.SetContent(this.CreateIntentFor(ViewModel.ListViewModel)); -> It works (But only without Parameters! How could I pass them here?)
spec.SetContent(this.CreateIntentFor<ListViewModel>(new { parameter = App.indicatorActive })); //Exception (on the next Line)
TabHost.AddTab(spec);
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
}
}
(App.indicatorActive 是我要传递的参数,它在 App.cs 中:(public static string indicatorActive = "Active";
)
我的 ListViewModel 看起来像这样:
public class ListViewModel : BaseViewModel
{
public ListViewModel(string parameter)
{
}
}
错误:
Unhandled Exception:
Cirrious.CrossCore.Exceptions.MvxException: Failed to load ViewModel for type
INApplikationsMonitor.Core.ViewModels.ListViewModel from locator MvxDefaultViewModelLocator