[英]Navigation problems with MVVMLight
尝试使用MVVMLight导航时遇到了几个问题。
在iOS上,我使用以下代码在AppDelegate / FinishedLoading中创建了NavigationService
var nav = new NavigationService();
nav.Configure(ViewModelLocator.MainPageKey, "MainPage");
nav.Configure(ViewModelLocator.MapPageKey, "MapPage");
// iOS uses the UINavigtionController to move between pages, so will we
nav.Initialize(Window.RootViewController as UINavigationController);
// finally register the service with SimpleIoc
SimpleIoc.Default.Register<INavigationService>(() => nav);
当我使用NavigateTo在两个页面之间移动时,我不断收到相同的错误,询问是否调用了NavigationService.Initialize。 显然我有。 第一个ViewController显示没有问题。
在Android上,第二个Activity再次遇到问题,但是出现了另一个错误。
我在NavigateTo中将List <double>作为对象参数传递,然后在Activity中,使用以下命令检索传递的对象
void GetDataFromViewModel()
{
var NavService = (NavigationService)SimpleIoc.Default.GetInstance<INavigationService>();
var data = NavService.GetAndRemoveParameter<object>(Intent) as List<double>;
if (data != null)
{
ViewModel.Latitude = data[0];
ViewModel.Longitude = data[1];
}
}
问题是在我的OnCreate方法中的base.OnCreate之后,应用程序崩溃并显示错误
UNHANDLED EXCEPTION:
[MonoDroid] System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Microsoft.Practices.ServiceLocation.ActivationException: Type not found in cache: System.Object.
我的NavigateTo行看起来像这样
INavigationService navigationService;
...code
navigationService.NavigateTo(ViewModelLocator.MapPageKey, new List<double> { Latitude, Longitude });
这让我难过!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.