Passing Parameters Between Pages

Posted: June 19, 2011 in Windows Phone 7 & Mango

Passing parameters between pages in Windows Phone 7 is similar to programming for the web where we make use of QueryString . You can pass the details from one page to another as follows:

private void Button1_Click(object sender, RoutedEventArgs e)
{
  NavigationService.Navigate(new Uri("/YourFolder/YourFile.xaml?YourParameterName=YourParameterValue", UriKind.Relative));
}

Now for the page for being navigated to, we can extract the parameter as follows:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
  base.OnNavigatedTo(e);
  string YourParameterValue = NavigationContext.QueryString["YourParameterName"];
}

To pass through multiple parameters between pages, you can do the following:

private void Button1_Click(object sender, RoutedEventArgs e)
{
  NavigationService.Navigate(new Uri("/YourFolder/YourFile.xaml?YourParameterName1=YourParameterValue1&YourParameterName2=YourParameterValue2", UriKind.Relative));
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s