Windows apps
Collapse the table of content
Expand the table of content
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.

Page.OnNavigatedTo Method


Called when a page becomes the active page in a frame.

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

protected virtual void OnNavigatedTo(
	NavigationEventArgs e


Type: System.Windows.Navigation.NavigationEventArgs
An object that contains the event data.

You override the OnNavigatedTo method to examine the navigation request and prepare the page for display. For example, you can load the requested data and enable or disable visual elements.

Typically, you use the OnNavigatedTo method instead of creating an event handler for the Loaded event. The OnNavigatedTo method is preferable because it is only called once for each time the page becomes active. The Silverlight framework raises the Loaded event each time the element is added to the visual tree, which potentially can happen more than once when activating a page.

The OnNavigatedTo method is called for each request, even when the page is retrieved from the cache. You should include in this method code that must be executed for each request rather than placing that code in the Page constructor.

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"];
        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);


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

© 2017 Microsoft