Export (0) Print
Expand All

Page.NavigationContext Property

Gets an object that contains information about the navigation request.

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

public NavigationContext NavigationContext { get; }

Property Value

Type: System.Windows.Navigation.NavigationContext
An object that contains information about the navigation request.

When you retrieve an instance of the NavigationContext class through the NavigationContext property, you use the NavigationContext object to obtain information about the navigation request, such as the query string values and uniform resource identifier. You can use these values to generate the desired state of a page for a navigation request. For example, you may retrieve a query string value to determine which record from a data set to display.

The following example shows how to override the OnNavigatedTo method 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:
© 2014 Microsoft