Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

NavigationContext Class

Silverlight

Represents the state of a navigation operation.

System.Object
  System.Windows.Navigation.NavigationContext

Namespace:  System.Windows.Navigation
Assembly:  System.Windows.Controls.Navigation (in System.Windows.Controls.Navigation.dll)
public sealed class NavigationContext

The NavigationContext type exposes the following members.

  NameDescription
Public propertyQueryStringGets a collection of query string values.
Top
  NameDescription
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

You use the NavigationContext class to retrieve the query string values for a navigation request. With the query string values, you can generate the desired state of a page for a navigation request. For example, you can store in the query string the identifier of the record you wish to display on a page.

To access an instance of the NavigationContext class, you use the NavigationContext property of the Page class.

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.