×
Namespaces

Variants
Actions
Revision as of 08:31, 30 November 2012 by hamishwillee (Talk | contribs)

How to pass strings between pages on Windows Phone

From Nokia Developer Wiki
Jump to: navigation, search

This article shows how to pass parameters during page navigation on Windows Phone 7.

NavigationService

NavigationService enables to download content within the context of browser style navigation. There are 2 ways to navigate content:

  1. To navigate the content we need to use Navigate() method of NavigationService and passing the object to it.
    • NavigationService.Navigate(Object)
    • NavigationService.Navigate(Object, Object)
  2. To navigate the content between pages we can use another overload of Navigate() method which takes a uniform resource identifier (URI) as one of the parameters and send the object to this URI:
    • NavigationService.Navigate(Uri)
    • NavigationService.Navigate(Uri, Object)
    • NavigationService.Navigate(Uri, Object, Boolean)

When content is navigated through a URI, NavigationService will return an object that contains the content.

Code Example

Let’s see an example of how to navigate content between pages.

Consider we have 2 pages – page1, page2. On click of submit button on page1,we need to send some data to Page2.

Code for submit button on Page1

private void submit_click(Object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri(/Page2.xaml?msg=+ txtName.text,Uri.Relative) );
}

Code for retrieving data on Page2

protected override void onNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.onNavigatedTo(e);
string msg;
if(NavigationContext.QueryString.TryGetValue(“msg”,out msg))
{
string name = msg;
}
}
WP Metro Icon UI.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
CompatibilityArticle
Created: SeemaB (25 Sep 2011)
Last edited: hamishwillee (30 Nov 2012)
492 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×