Information
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.

NavigationService.GetNavigationService Method

Gets the NavigationService object for the navigator (NavigationWindow, Frame) whose content contains the specified DependencyObject.

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

public static NavigationService GetNavigationService (
	DependencyObject dependencyObject
)
public static NavigationService GetNavigationService (
	DependencyObject dependencyObject
)
public static function GetNavigationService (
	dependencyObject : DependencyObject
) : NavigationService
You cannot use methods in XAML.

Parameters

dependencyObject

The DependencyObject in content that is hosted by a navigator.

Return Value

The NavigationService object for the navigator (NavigationWindow, Frame) whose content contains the specified DependencyObject; otherwise, null is returned when the dependencyObject:
  • Is a NavigationWindow or a

  • Is a Frame that is hosted by another navigator, and whose JournalOwnership property is set to UsesParentJournal.

  • Is not part of content that is hosted by a navigator.

Exception typeCondition

ArgumentNullException

The dependencyObject parameter is null.

As a shortcut, Page can discover its NavigationService by inspecting its Page.NavigationService property. Otherwise, content that is not a page can use GetNavigationService.

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

	...

    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft