Question

My first C#/Xaml-experience was Windows Phone 8 where navigation worked like this:

NavigationService.Navigate(new Uri("/MyPage.xaml", UriKind.Relative));

Which meant that I could replace the String "/MyPage.xaml" by anything I needed and go to that page.

Is something similar possible with Windows Store Apps?

this.Frame.Navigate(typeof(MyPage), UriKind.Relative);

MyPage isn't a string here so I can't simply replace it while the app is running. Still any way to do this?

What I am doing is: I use a ListBox that gets it's data from a bound viewModel. There I wanted to store the target where the app should navigate to after a SelectionChanged Event is fired.

Était-ce utile?

La solution

You can use it like below if you get the string with namespace.

this.Frame.Navigate(Type.GetType("Namespace.PageName"));

Autres conseils

Yes you can pass the url of the page on selection changed and load the corresponding dataContext

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    var title = NavigationContext.QueryString["title"];
    (DataContext as ImagePageViewModel).Load(title);
}

Follow this example which would fulfill your requirement

page-navigation-in-windows-phone-and-windows-8

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top