1

I've a class

class PTD
{
  public string Player1 { get; set; }
  public string Player2 { get; set; }
}

And a Page1 have 2 text boxes and 1 button. The Button Click Method have following code:

PTD ptd = new PTD();
ptd.Player1=textbox1.text.ToString();
ptd.Player2=textbox2.text.ToString();

NavigationService.Navigate(new Uri ("/Page2.xaml?msg=", UriKind.RelativeOrAbsolute));

On Page2 I have 2 text blocks where i want my class data to appear on navigation. What additional code should i write to perform this action?

Chris Shao
  • 8,231
  • 3
  • 39
  • 37

1 Answers1

0

In Windows Phone 8.0 and Windows Phone Silverlight 8.1, you can use NavigationService to do page navigations.

You can pass strings as parameter of 'Navigation Uri'.

NavigationService.Navigate(new Uri (
    string.Format("/Page2.xaml?player1={0}&player2={1}", ptd.Player1, ptd.Player2), 
    UriKind.RelativeOrAbsolute));

Then in Page2, you can receive the 2 params in OnNavigatedTo method like this:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    string player1;
    NavigationContext.QueryString.TryGetValue("player1", out player1);
    string player2;
    NavigationContext.QueryString.TryGetValue("player2", out player2);
}
Chris Shao
  • 8,231
  • 3
  • 39
  • 37