0

In Windows Phone 8.1 there is any way to navigate from one page to another using an string instead of a Type?

There is no reflection and Frame.Navigate only accepts type.

Thank you.

Black Cid
  • 438
  • 1
  • 7
  • 21

2 Answers2

1

I agree with Kai Brummund. You should write a NavigationService. A good example of a navigation service is the MVVM light navigation service. Here you can find the source code.

Corcus
  • 1,070
  • 7
  • 25
0

Or... you just can use MVVMLight which comes with an integrated NavigationService (INavigationService). You set it in ViewModelLocator like this:

private const string URL_DETALLE = "/View/DetalleView.xaml";
public ViewModelLocator()
{
    // ...

    var navigationService = this.CreateNavigationService();

    if (!SimpleIoc.Default.IsRegistered<INavigationService>())
    {
        SimpleIoc.Default.Register<INavigationService>(() => navigationService);
    }

    //...
}   

private INavigationService CreateNavigationService()
{
    var navigationService = new NavigationService();
    navigationService.Configure(URL_DETALLE, typeof(DetalleView));

    return navigationService;
}

Then in your VM constructor you will recieve this navigaton service and you can use it this way:

private INavigationService navigationService;
public DetalleViewModel(INavigationService navigationService)
{
    this.navigationService = navigationService;
    this.navigationService.NavigateTo(ViewModelLocator.URL_DETALLE);
}

Hope it helps ;)

Cabuxa.Mapache
  • 762
  • 1
  • 7
  • 19