Поделиться через


NavigatingCancelEventArgs Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Provides data for the OnNavigatingFrom method and the Navigating event.

Inheritance Hierarchy

System.Object
  System.EventArgs
    System.ComponentModel.CancelEventArgs
      System.Windows.Navigation.NavigatingCancelEventArgs

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

Syntax

'Declaration
<TypeForwardedFromAttribute("System.Windows.Controls.Navigation, Version=2.0.5.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")> _
Public NotInheritable Class NavigatingCancelEventArgs _
    Inherits CancelEventArgs
[TypeForwardedFromAttribute("System.Windows.Controls.Navigation, Version=2.0.5.0, Culture=Neutral, PublicKeyToken=31bf3856ad364e35")]
public sealed class NavigatingCancelEventArgs : CancelEventArgs

The NavigatingCancelEventArgs type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows Phone NavigatingCancelEventArgs(Uri, NavigationMode) Initializes a new instance of the NavigatingCancelEventArgs class, based on URI and mode.
Public methodSupported by Silverlight for Windows Phone NavigatingCancelEventArgs(Uri, NavigationMode, Boolean, Boolean) Initializes a new instance of the NavigatingCancelEventArgs class, setting all initial property values.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows Phone Cancel Gets or sets a value that indicates whether the operation should be canceled. (Inherited from CancelEventArgs.)
Public propertySupported by Silverlight for Windows Phone IsCancelable Gets a value that indicates whether you can cancel the navigation.
Public propertySupported by Silverlight for Windows Phone IsNavigationInitiator Gets a value that indicates whether the current application is the origin and destination of the navigation.
Public propertySupported by Silverlight for Windows Phone NavigationMode Gets a value that indicates the type of navigation that is occurring.
Public propertySupported by Silverlight for Windows Phone Uri Gets the uniform resource identifier (URI) for the content that is being navigated to.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows Phone Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone GetType Gets the Type of the current instance. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows Phone MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows Phone ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

The NavigatingCancelEventArgs object provides event arguments for the OnNavigatingFrom method on a Page or the Navigating event. The Navigating event is raised or the OnNavigatingFrom method is called just before navigating from a page.

You can prevent a navigation request by setting the Cancel property to true. To evaluate a navigation request, you can examine the values of the NavigationMode and Uri properties.

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

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.