Page.OnNavigatingFrom Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Called just before a page is no longer the active page in a frame.
Namespace: System.Windows.Controls
Assembly: System.Windows.Controls.Navigation (in System.Windows.Controls.Navigation.dll)
Syntax
'Declaration
Protected Overridable Sub OnNavigatingFrom ( _
e As NavigatingCancelEventArgs _
)
protected virtual void OnNavigatingFrom(
NavigatingCancelEventArgs e
)
Parameters
- e
Type: System.Windows.Navigation.NavigatingCancelEventArgs
An object that contains the event data.
Remarks
You override the OnNavigatingFrom method to perform any actions on the page just before it becomes inactive.
Typically, you can use the OnNavigatingFrom method instead of creating an event handler for the Navigating event. Using the OnNavigatingFrom method is preferable because you do not have to remove the event handler from the NavigationService object to avoid object lifetime issues.
Examples
The following example shows how to override the OnNavigatingFrom method and use the NavigatingCancelEventArgs object to determine if a child window is displayed.
Partial Public Class About
Inherits Page
Public Sub New()
InitializeComponent()
End Sub
Protected Overrides Sub OnNavigatingFrom(ByVal e As System.Windows.Navigation.NavigatingCancelEventArgs)
If (e.Uri.ToString().Contains("/Home")) Then
Dim surveyChildWindow As New SurveyWindow
surveyChildWindow.Show()
End If
MyBase.OnNavigatingFrom(e)
End Sub
End Class
public partial class About : Page
{
public About()
{
InitializeComponent();
}
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (e.Uri.ToString().Contains("/Home"))
{
SurveyWindow surveyChildWindow = new SurveyWindow();
surveyChildWindow.Show();
}
base.OnNavigatingFrom(e);
}
}
Version Information
Silverlight
Supported in: 5, 4, 3
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
See Also