Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

NavigationContext.QueryString Property

Silverlight

Gets a collection of query string values.

Namespace:  System.Windows.Navigation
Assembly:  System.Windows.Controls.Navigation (in System.Windows.Controls.Navigation.dll)

public IDictionary<string, string> QueryString { get; private set; }

Property Value

Type: System.Collections.Generic.IDictionary<String, String>
A collection that contains the query string values.

You retrieve values from the query string to generate the desired state of a page for a navigation request. A navigation request with query string values includes the query string key/value pairs after a question mark (?) delimiter. For example, you can store in the query string the identifier of the record you wish to display on a page, such as /Views/Product.xaml?productid=45&format=long. The values from the query string are decoded before being stored in the QueryString collection.

The following example shows how to override the OnNavigatedTo in a Silverlight page and obtain a query string value from the NavigationContext object. The query string value is used to determine which product is retrieved from a data service and displayed in the page.


protected override void OnNavigatedTo(NavigationEventArgs e)
{
    string productID;
    DataServiceContext svcContext = 
        new DataServiceContext(new Uri("AdventureWorks.svc", UriKind.Relative));

    if (this.NavigationContext.QueryString.ContainsKey("ProductId"))
    {
        productID = this.NavigationContext.QueryString["ProductId"];
    }
    else
    {
        productID = App.Current.Resources["FeaturedProductID"].ToString();
    }

    svcContext.BeginExecute<Product>(new Uri("Product(" + productID + ")", 
        UriKind.Relative), loadProductCallback, svcContext);

}

private void loadProductCallback(IAsyncResult asyncResult)
{
    DataServiceContext context = asyncResult.AsyncState as DataServiceContext;

    ListBox1.DataContext = context.EndExecute<Product>(asyncResult);
}


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

Show:
© 2016 Microsoft