1

I am a problem about how to pass the value from one form to another in Windows Phone 7, I am new to silverlight concept and don't know about how to pass the values between the forms. I have tried searching a lot. But all in vain.

Please help me if anyone knows.

Thanks BHAVIK GOYAL

Bhavik Goyal
  • 2,786
  • 6
  • 23
  • 42
  • possible duplicate of [wp7 passing data from page to page](http://stackoverflow.com/questions/4953491/wp7-passing-data-from-page-to-page) – Matt Lacey Mar 07 '11 at 10:54
  • I go through a few different methods to pass parameters in [this answer](http://stackoverflow.com/a/12444817/200442). It goes over using query string parameters, constructor arguments and a few others. – Daniel Little Sep 24 '12 at 03:32

3 Answers3

5

This might help: Passing values to Windows Phone 7 pages: URI paremeters and QueryString

To pass parameters while navigating to another page you have to specify them in Uri path. You can pass parameters only in string format (same way it is done for most of websites) using ‘?’ character and ‘&’ as a separator. In following example I am passing two parameters to AnotherPage.xaml. Keep in mind that parameters stored in NavigationContext.

string parameter1Value = "test1";
string parameter2Value = "test2";
NavigationService.Navigate(
    new Uri(string.Format("/AnotherPage.xaml?myparameter1={0}&myparameter2={1}",
        parameter1Value, parameter2Value),
        UriKind.Relative));

Now we need to get those parameters on AnotherPage.xaml page. To do so you need to override the OnNavigatedTo method and get those parameters and their values from NavigationContext.

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

    string myparameter1Value = null;
    string myparameter2Value = null;

    NavigationContext.QueryString.TryGetValue("myparameter1", out myparameter1Value);
    NavigationContext.QueryString.TryGetValue("myparameter2", out myparameter2Value);
}
Bhavik Goyal
  • 2,786
  • 6
  • 23
  • 42
abramlimpin
  • 5,027
  • 11
  • 58
  • 97
2

here is the detailed explanation how to pass data among pages in Windows Phone 7. It also includes sample code for all 4 procedures

http://nishantcop.blogspot.com/2011/08/passing-data-between-pages-in-windows.html

nishantcop
  • 977
  • 1
  • 8
  • 24
1

Here's a simple project which uses a querystring to pass a value between two pages. http://dl.dropbox.com/u/129101/Panorama_querystring.zip

William Melani
  • 4,270
  • 1
  • 21
  • 44