Pass more than one parameter to another page

2

I am doing a windows phone application, in which the main screen (first screen) is made a calculation, and the result is displayed on a second screen.

I was able to make the 'connection' between the two screens as follows

On page 1 or main screen:

     private void button2_Click(object sender, RoutedEventArgs e)
    {

        Uri caminho = new Uri("/Paginas/Resolucao.xaml?parametro=" textBlock1.Text, UriKind.Relative);
        NavigationService.Navigate(caminho);

    }

On page 2 or secondary screen

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

        string parametroRecebido1 = NavigationContext.QueryString["parametro"];
        textBlock2.Text = parametroRecebido1;       
    }

But with these 'methods' I can only pass a variable (the variable that stays in textBlock1) I saw this link in Option3 that to pass more than one variable would have to be made the following code:

On page 1 or main screen;

    private void btnNavigate_Click(object sender, RoutedEventArgs e)
    {
    NavigationService.Navigate(new Uri("/Page1.xaml?parameter1=p1& parameter2=p2",UriKind.Relative));
    }

Second screen;

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
     base.OnNavigatedTo(e);
     string parameterValue1 = NavigationContext.QueryString["parameter1"];
     string parameterValue2 = NavigationContext.QueryString["parameter2"];  
    }

asked by anonymous 28.02.2015 / 19:58

2 answers

1

You can use IsolatedStorageSettings to store the variables before going to the next screen.

To store:

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
settings["parameter1"] = this.txtboxDescription;
settings["parameter2"] = this.txtboxDescription2;
settings.Save();

To get, after you have moved to the next page (NavigationService.Navigate (new Uri ("/ Page1.xaml ')):

IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
string txtboxDescription2 = settings["parameter1"];
string txtboxDescription2 = settings["parameter2"];

If it is not string, you can cast a value:

Boolean saveLogin = (bool)settings["saveLogin"];
    
28.02.2015 / 21:15
1

SOLUTION

I was informed by the user link that my error was only in the use of the quotation marks ("). corrected error the code looks like this:

Home screen or first page

private void button2_Click(object sender, RoutedEventArgs e)
{
Uri caminho = new Uri("/Paginas/Resolucao.xaml?parametro="+n1+"&parametro2="+n2, UriKind.Relative);
NavigationService.Navigate(caminho);

}

My mistake was to separate & of the string and put it outside the quotation marks (").

In case n1 and n2 are my variables;

On the Second Screen it will look like this:

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

    string parametroRecebido1 = NavigationContext.QueryString["parametro"]; 
    string parametroRecebido2 = NavigationContext.QueryString["parametro2"];


   textBlock1.Text = parametroRecebido1;
   textBlock2.Text = parametroRecebido2;

}

If you want to change from 1 to as many variables as you want, you will do the following: In this case, I will give you three variables (n1, n2, n3)

On the Main Screen

private void button2_Click(object sender, RoutedEventArgs e)
{
Uri caminho = new Uri("/Paginas/Resolucao.xaml?parametro="+n1+"&parametro2="+n2+"&parametro3="+n3 UriKind.Relative);
NavigationService.Navigate(caminho);

}

On the second screen

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

    string parametroRecebido1 = NavigationContext.QueryString["parametro"]; 
    string parametroRecebido2 = NavigationContext.QueryString["parametro2"];
    string parametroRecebido3 = NavigationContext.QueryString["parametro3"];

   textBlock1.Text = parametroRecebido1;
   textBlock2.Text = parametroRecebido2;
   textBlock3.Text = parametroRecebido3;

}
    
01.03.2015 / 05:41