Usman ur Rehman Ahmed's blog

Use of Navigation Context in Windows Phone 7

This class provides an important property QueryString that allows you to pass information between two phone application pages just as you would do for web pages. An example is shown below,

    private void button1_Click(object sender, RoutedEventArgs e)
    {
            NavigationService.Navigate(new Uri("/Page1.xaml?OrderNo=123456",UriKind.Relative));
    }

 However it should be noted that on the navigated page, the query string paramters be received in the event OnNavigatedTo, 

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        string OrderNo = this.NavigationContext.QueryString[“OrderNo”];
        //Use the OrderNo here
        base.OnNavigatedTo(e);
    }

Query string items are supposed to be & seperated and the class provides a method to check query string collectionf or a given key,

 

    string OrderNo = string.Empty;
    if (NavigationContext.QueryString.TryGetValue("OrderNo", out OrderNo))
    {
        //The code will only reach here if OrderNo was found in query string and                    
        //retrieved properly
    }

11
To Posterous, Love Metalab