Called when a page becomes the active page in a frame.
Assembly: System.Windows.Controls.Navigation (in System.Windows.Controls.Navigation.dll)
You override the 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 method instead of creating an event handler for the Loaded event. The 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 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 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 Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs) Dim productID As String Dim svcContext As DataServiceContext svcContext = New DataServiceContext(New Uri("AdventureWorks.svc", _ UriKind.Relative)) If (Me.NavigationContext.QueryString.ContainsKey("ProductId")) Then productID = Me.NavigationContext.QueryString("ProductId") Else productID = App.Current.Resources("FeaturedProductID").ToString() End If svcContext.BeginExecute(Of Product)(New Uri("Product(" + productID + ")", _ UriKind.Relative), AddressOf loadProductCallback, svcContext) End Sub Private Sub loadProductCallback(ByVal asyncResult As IAsyncResult) Dim context As DataServiceContext context = asyncResult.AsyncState ListBox1.DataContext = context.EndExecute(Of Product)(asyncResult) End Sub
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.