NavigationService.GetNavigationService(DependencyObject) Método

Definição

Obtém uma referência ao NavigationService do navegador cujo conteúdo contém o DependencyObject especificado.

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

Parâmetros

dependencyObject
DependencyObject

O DependencyObject no conteúdo que é hospedado por um navegador.

Retornos

Uma referência ao NavigationService do navegador cujo conteúdo contém o DependencyObject especificado; pode ser null em alguns casos.

Exceções

O parâmetro dependencyObject é null.

Exemplos

O exemplo a seguir mostra como um UserControl pode recuperar um serviço de navegação chamando 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

Comentários

Um navegador tem um NavigationService que manipula a navegação de conteúdo. O WPF tem dois navegadores: NavigationWindow e Frame. Para processar solicitações de navegação e gerenciar o tempo de vida de navegação, um navegador usa o serviço de navegação WPF, que é implementado como a NavigationService classe . O conteúdo hospedado por um navegador pode obter uma referência ao navegador NavigationService chamando o GetNavigationService método .

GetNavigationService retorna null quando o dependencyObject:

O WPF oferece dois atalhos para adquirir uma referência ao NavigationService:

Aplica-se a