Namespaces
Variants
Actions

Passing parameters while navigating between pages on Windows Phone

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;
}
}
Article Metadata

Article
Created: SeemaB (25 Sep 2011)
Last edited: hamishwillee (10 Apr 2013)
This page was last modified on 10 April 2013, at 04:30.
718 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved