NavigationService.GetNavigationService(DependencyObject) Metodo

Definizione

Ottiene un riferimento a NavigationService per lo strumento di spostamento il cui contenuto include l'oggetto DependencyObject specificato.

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

Parametri

dependencyObject
DependencyObject

DependencyObject nel contenuto ospitato in uno strumento di spostamento.

Restituisce

Riferimento a NavigationService per lo strumento di spostamento il cui contenuto include l'oggetto DependencyObject specificato. In alcuni casi può essere null.

Eccezioni

Il valore del parametro dependencyObject è null.

Esempio

Nell'esempio seguente viene illustrato come UserControl recuperare un servizio di spostamento chiamando 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

Commenti

Uno strumento di navigazione dispone di un NavigationService oggetto che gestisce lo spostamento del contenuto. WPF include due navigatori: NavigationWindow e Frame. Per elaborare le richieste di spostamento e gestire la durata di spostamento, uno strumento di navigazione usa il servizio di spostamento WPF, implementato come NavigationService classe. Il contenuto ospitato da uno strumento di navigazione può ottenere un riferimento al navigatore NavigationService chiamando il GetNavigationService metodo .

GetNavigationServicerestituisce null quando :dependencyObject

WPF offre due collegamenti per l'acquisizione NavigationServicedi un riferimento a :

Si applica a