1
votes

I am making a Universal winrt app using mvvm light. In ViewModelLocator I've registered my view in the builtin NavigationService of mvvm light

SimpleIoc.Default.Register<INavigationService>(() =>
{
    var navigationService = new NavigationService();
    navigationService.Configure("PreRegisterPage", typeof(PreRegisterPage));
    return navigationService;
});

But when I try to navigate to that page using this code,

 _navigationService.NavigateTo("PreRegisterPage");

It throws this exception

No such page: PreRegisterPage. Did you forget to call NavigationService.Configure? Parameter name: pageKey

Am I missing something?

1
There is some context missing.Friedrich
Check the inner exception. It might be interpreted incorrectly.user1228
The inner exception is nullMr. Hello

1 Answers

0
votes

You probably forgot to pass an INavigationService object in the ViewModel ctor, here how your ViewModel should looks like:

  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;           
    }
}