Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

NavigationService.GetNavigationService(DependencyObject) Method

Definition

Namespace:
System.Windows.Navigation
Assembly:
PresentationFramework.dll

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Gets a reference to the NavigationService for the navigator whose content contains the specified DependencyObject.

public:
 static System::Windows::Navigation::NavigationService ^ GetNavigationService(System::Windows::DependencyObject ^ dependencyObject);
public static System.Windows.Navigation.NavigationService GetNavigationService(System.Windows.DependencyObject dependencyObject);
static member GetNavigationService : System.Windows.DependencyObject -> System.Windows.Navigation.NavigationService
Public Shared Function GetNavigationService (dependencyObject As DependencyObject) As NavigationService

Parameters

dependencyObject
DependencyObject

The DependencyObject in content that is hosted by a navigator.

Returns

A reference to the NavigationService for the navigator whose content contains the specified DependencyObject; can be null in some cases.

Exceptions

The dependencyObject parameter is null.

Examples

The following example shows how a UserControl can retrieve a navigation service by calling GetNavigationService.

void getNavigationServiceButton_Click(object sender, RoutedEventArgs e) {
 // Retrieve first navigation service up the content tree
 NavigationService svc = NavigationService.GetNavigationService(this.getNavigationServiceButton);
 if (svc != null)
 {
 // Use navigation service
Private Sub getNavigationServiceButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
 ' Retrieve first navigation service up the content tree
 Dim svc As NavigationService = NavigationService.GetNavigationService(Me.getNavigationServiceButton)
 If svc IsNot Nothing Then
 ' Use navigation service
 }
}
 End If
End Sub

Remarks

A navigator has a NavigationService that handles content navigation. WPF has two navigators: NavigationWindow and Frame. To process navigation requests and manage navigation lifetime, a navigator uses the WPF navigation service, which is implemented as the NavigationService class. Content that is hosted by a navigator can get a reference to the navigator's NavigationService by calling the GetNavigationService method.

GetNavigationService returns null when the dependencyObject:

WPF offers two shortcuts for acquiring a reference to the NavigationService:

Applies to


Feedback

Was this page helpful?