Data Transfer between Two Pages in Windows Phone

 
 

Step 1:- Create a Page in your project named as ‘NavigationPage.xaml’


Step 2:- Add 2 Texboxes named ‘TextBox1’ & ‘TextBox2’ respectivaly and a Button on this page with Content=’Navigate’ and create the click event of that button by clicking on the button.


Step 3:- Create a new page named as ‘NextPage.xaml’

Step 4:- Add a TextBlock named ‘TextBlock1’ on ‘NextPage.xaml’.

Step 5:- Write the code on the .cs file of ‘NavigationPage.xaml’ page as mentioned below:

private void Button_Click_1(object sender, RoutedEventArgs e) {

Uri url = new Uri(string.Format("/NextPage.xaml?Val1={0}&Val2={1}",

TextBox1.Text,TextBox2.Text)),UriKind.RelativeOrAbsolute);

NavigationService.Navigate(url);

}

Note:- ‘/ ’ is necessary before the path of your page which you want to show after the navigation or redirection like "/NextPage.xaml".

Step 6:- Write the code on the .cs file of ‘NextPage.xaml’ page as mentioned below:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) {

         string strvalue1 = NavigationContext.QueryString["Val1"];

         string strvalue2 = NavigationContext.QueryString["Val2"];

         TextBlock1.Text = strvalue1 + " " + strvalue2;

         base.OnNavigatedTo(e);

}

Step 7:- Run the Application after setting the ‘NavigationPage.xaml’ as Navigation Page(Start Page) in WMAppManifest.xaml which exist in properties Folder

Step 8:- Click on the Navigate button after filling the some text in both TextBox and see the output on Next Page.