Search code examples
windows-phone-8navigation

How to put something extra while navigate another page in windows phone


I created a listpage and when i click in general button in main page i have to navigate the page to listpage and put something extra while navigating it in order to understand which page its going to get the list, otherwise i have to create lots of listpages for every category

    private void btn_general_Click(object sender, RoutedEventArgs e)
    {
         NavigationService.Navigate(new Uri("/ListPage.xaml", UriKind.Relative)); 
    }

Solution

  • You can use the page URI to put contextual data:

    NavigationService.Navigate(new Uri("/ListPage.xaml?list=list1", UriKind.Relative)); 
    

    In ListPage, you can then retrieve that data by looking into the NavigationContext.QueryString property:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (NavigationContext.QueryString.ContainsKey("list"))
        {
            string list = NavigationContext.QueryString["list"];
            // whatever
        }
    }