我正在使用mvvm light创建一个Universal winrt应用程序。在ViewModelLocator中,我在mvvm light的内置NavigationService中注册了我的视图
SimpleIoc.Default.Register<INavigationService>(() =>
{
var navigationService = new NavigationService();
navigationService.Configure("PreRegisterPage", typeof(PreRegisterPage));
return navigationService;
});
但是当我尝试使用此代码导航到该页面时,
_navigationService.NavigateTo("PreRegisterPage");
抛出此异常
没有这样的页面:PreRegisterPage。你忘记打电话了吗? NavigationService.Configure?参数名称:pageKey
我错过了什么吗?
答案 0 :(得分:0)
您可能忘记在INavigationService
ctor中传递ViewModel
个对象,此处ViewModel
应如何显示:
public class MainViewModel : ViewModelBase
{
private INavigationService _navigationService;
private RelayCommand _navigateCommand;
public RelayCommand NavigateCommand
{
get
{
return _navigateCommand
?? (_navigateCommand = new RelayCommand(
() =>
{
_navigationService.NavigateTo("PreRegisterPage");
}));
}
}
public MainViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
}
}