Alexander V.
Alexander V.

Reputation: 1623

transfering a variable to another page in windows phone 7

Im trying to transfer a string-variable to another page. In Main Page code looks like:

 Page p1 = new Page1();
 NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
 p1.lalala("sdfsdfsd");

in Page1 code looks like:

public partial class Page1 : PhoneApplicationPage
{
    public Page1()
    {
        InitializeComponent();
    }

    public void lalala(string i)
    {
        textBlock1.Text = i;
    }
}

and of course, nothing happens, textblock remains empty. and should not, i know. i really don't know how i can quickly transfer to another page the value of a variable. I say thanks in advance and sorry for really stupid question.

Upvotes: 1

Views: 1544

Answers (1)

John Gardner
John Gardner

Reputation: 25146

pass it on the uri in navigate, like

NavigationService.Navigate(new Uri("/Page1.xaml?lalala=sdfsdfsd", UriKind.Relative)); 

and then retrieve it from the query string in the navigation event in Page1

string lalala = this.NavigationContext.QueryString["lalala"];
textBlock.Text = lalala;

Upvotes: 3

Related Questions