Windows Phone 8.1 navigate using string instead of a type

穿精又带淫゛_ 提交于 2019-12-11 19:57:11

问题


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.


回答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.




回答2:


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



来源:https://stackoverflow.com/questions/28157188/windows-phone-8-1-navigate-using-string-instead-of-a-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!