Introduction
In this article we will explore various ways of passing data between Windows Phone 7 pages. Let us assume that we have two pages in our application with the name "Page1.xaml" and "Page2.xaml". We will try to pass a value from Page1 to Page2 using different methods.
Using Fragments
We can use fragments in an URL to pass a value from Page1 to Page2.
In "Page1.xaml.cs", write the following code in a Button click event:
private void btnGo_Click(object sender, RoutedEventArgs e)
{
this.NavigationService.Navigate(new Uri("/Page2.xaml#Deepak"), UriKind.Relative);
}
To get a value in "Page2.xaml.cs", override the OnFragmentNavitation method:
protected override void OnFragmentNavigation(FragmentNavigationEventArgs e)
{
MessageBox.Show(e.Fragment);
}
Using QueryString
We can pass only one value using a fragment. To pass multiple values we should use QueryString.
Code to pass values in Page1.xaml.cs:
private void btnGo_Click(object sender, RoutedEventArgs e)
{
this.NavigationService.Navigate(new Uri("/frmMap.xaml?FirstName=Deepak&LastName=Sharma", UriKind.Relative));
}
Code to get values in Page2.xaml.cs:
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
string FirstName = NavigationContext.QueryString["FirstName"];
string LastName = NavigationContext.QueryString["LastName"];
MessageBox.Show(FirstName + ' ' + LastName);
}
Using public property in App.xaml
It acts as declaring a static global variable in "App.xaml.cs" and using it from any part of the application.
Declare a public property in "App.xaml.cs"

RaghavanandPosted Dec 10, 2012, 6:39 AM
nice article !! but i need information how to pass images using query string
Maria JohnsonPosted Feb 9, 2012, 11:21 PM
Hi Deepak. You have presented your article very nicely.
Abhi KumarPosted Feb 9, 2012, 11:05 PM
Nice article.
Nitin SinghPosted Feb 9, 2012, 10:55 PM
Thanks for sharing
Jessica StephenPosted Feb 9, 2012, 10:54 PM
good approach...