2
I’m making 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 already managed 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 is in the textBlock1) I saw on that site http://www.geekchamp.com/tips/how-to-pass-data-between-pages-in-windows-phone-alternatives on Option3 that in order to pass more than one variable the following code would have to be done:
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));
}
On the Second Screen;
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string parameterValue1 = NavigationContext.QueryString["parameter1"];
string parameterValue2 = NavigationContext.QueryString["parameter2"];
}
____ My question is this: : how do I pass for example my variables n1 and N2 in the first screen method
NavigationService.Navigate(new Uri("/Page1.xaml?parameter1=p1¶meter2=p2", UriKind.Relative));
___ I tried to fit my variables n1 and N2 into this line of code as follows: ---- But GAVE ERROR
NavigationService.Navigate(new Uri("/Page1.xaml?parameter1="+n1&+"parameter2=n2", UriKind.Relative));
___ I also tried to keep the code 'original' by modifying the name of the variables Thus:
NavigationService.Navigate(new Uri("/Page1.xaml?parameter1=n1¶meter2=n2", UriKind.Relative));
But when displaying the results it only displayed the words 'n1' and 'N2' and not the values stored there
Who can help I will be immensely grateful :D
Diego, you have missed only "" in the command: Navigationservice.Navigate(new Uri("/Page1.xaml?parameter1=" + n1 + "¶meter2=" + N2, Urikind.Relative)); - Prefer string. Format to avoid these problems.
– Malkaviano
Malkaviano, it worked here, I do not believe I broke my head for hours because of a " but now I know. Thank you aee
– Diego Leite
Good night friend does not post the answer within the question, we are not a simple forum, we are a Q&A, so you can answer your own question by clicking the answer button, plus it is not necessary to edit the title and write SOLVED, by marking the correct answer the question is already considered as solved. A good night
– Guilherme Nascimento
Friend I think you are confused, I said in the previous comment that writing SOLVED in the title is not necessary.
– Guilherme Nascimento
@Guilhermenascimento I was a little confused even hahaha, but I think it’s all right, sorry, it’s just that I started a few days ago at the forum
– Diego Leite
Precisely we are not forum, we are a community of questions and answers, here the scheme is more organized :) at first it seems boring is difficult, but the organization this through the tool itself make stackexchange communities much easier to moderate and organize.
– Guilherme Nascimento