1

I have to send the id that I get from a rest web service from page1.xaml to page2.xaml I tried this code:

Page1.xaml.cs:

private async void Grid1_Tapped(object sender, TappedRoutedEventArgs e)
        {
            UriString2 = "URL";

            int x= rootObject.posts[0].id;
            string uri = string.Format("/Page2.xaml?x={1}",x);

            //adding Navigation Statement
            this.Frame.Navigate(typeof(Page2), new Uri(uri, UriKind.Relative));

        }

Page2.xaml.cs:

 private async void Page_Loaded(object sender, RoutedEventArgs e)
           {
            int xx = Convert.ToInt32(NavigationContext.QueryString["x"]);
        }

this code doesn't work,I have an error "NavigationContext doesn't exist in this context",miss I anything :(

thanks for help

user3821206
  • 609
  • 1
  • 9
  • 22
  • 1
    I've seen a answer before, is this what you need? [How to pass value from one page to another page in the context of data binding?](http://stackoverflow.com/questions/23464060/how-to-pass-value-from-one-page-to-another-page-in-the-context-of-data-binding) – Oh My Dog Dec 12 '15 at 04:21

1 Answers1

1

For Navigation in UWP, you can use Frame.Navigate(typeof(TargetPage)); method to navigate from current page to target page.

You can see my answer for another question:Windows Phone 8.1 - Page Navigation

And in TargetPage, you can use NavigationParameter property to get navigation parameter.

private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
    var param = e.NavigationParameter;
}

And in you case, code should be:

SourcePage:

Frame.Navigate(typeof(SecondPage), rootObject.posts[0].id);

TargetPage:

private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
    string idStr = e.NavigationParameter as string;
    int id = int.Parse(idStr);
}
Community
  • 1
  • 1
Chris Shao
  • 8,231
  • 3
  • 39
  • 37