feofan
feofan

Reputation: 33

Navigation and Query parameter to another page Windows Phone 8.1

I have Windows Phone 8.1 app and I need to navigate from a main page to page "pizdec" with parameteres.

I have a cod which can do it in WP8.0, but how car rewrite it in code WP8.1, I don't know.

Example:

private void listbox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
   {
     if (listbox1.SelectedItem != null)
     {
        var file = listbox1.SelectedItem as StorageFile;
        NavigationService.Navigate(new Uri("/pizdec.xaml?filename=" + file.Name, UriKind.Relative));
        listbox1.SelectedItem = null;
     }

I know that I need use this.Frame.Navigate() , but I do not understand how to rewrite it to 8.1

Code from pizdec.xaml:

protected override void OnNavigatedTo(NavigationEventArgs e)
   {
      base.OnNavigatedTo(e);
      string filename;

    if(NavigationContext.QueryString.TryGetValue("filename",out filename))
    {
        DisplayFile(filename);
    }

And NavigationContext, which no in 8.1

Please help

Upvotes: 0

Views: 187

Answers (1)

Abhishek
Abhishek

Reputation: 7035

You use following,

Frame.Navigate(typeof(pizdec), param); //a Windows app syntax. param is parameters you want to pass to pizdec.xaml

You can access the paramaters in next page as follows,

string filename = e.NavigationParameter as string;

Microsoft is trying to make syntax of Windows & windows phone app similar, hence the change. More info here

Upvotes: 1

Related Questions