0

我将 WPF 与导航服务一起使用。在导航下一页之前,我需要了解情况。导航下一页“之前”是否有任何事件?

Navigate("MyPage1.xaml")
Navigate("MyPage2.xaml")'now, I need a event which shows me : FromPage("MyPage1.xaml") before navigating to "MyPage2.xaml".

代码示例

Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
    Application.NavigationService = Me.ContentFrame.NavigationService
End Sub

Class Application
    ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException
    ' can be handled in this file.
    Public Shared NavigationService As NavigationService
End Class



Private Sub ContentFrame_Navigated(ByVal sender As Object, ByVal e As System.Windows.Navigation.NavigationEventArgs) Handles ContentFrame.Navigated
    If Application.cLang Is Nothing Then Call InitializeLanguage()
    'The following Welcome page is never visible because e.Uri is always the NEXT page
    If e.Uri IsNot Nothing AndAlso (e.Uri.ToString.Contains("Pages/PageWelcome.xaml")) Then
        Call UpdateLanguageCombobox()
    End If
End Sub



Private Sub ContentFrame_Navigating(ByVal sender As Object, ByVal e As System.Windows.Navigation.NavigatingCancelEventArgs) Handles ContentFrame.Navigating
    Dim Uri As Uri = CType(sender, Frame).Source
    If Application.cLang Is Nothing Then Call InitializeLanguage()
    'The following Welcome page is never visible because e.Uri is always the NEXT page
    If e.Uri IsNot Nothing AndAlso (e.Uri.ToString.Contains("Pages/PageWelcome.xaml")) Then
        'Call UpdateLanguageCombobox()
    End If
End Sub
4

2 回答 2

1

是的!尝试导航事件。它在请求导航时引发。有关 NavigationServices 事件的更多信息,请参见http://msdn.microsoft.com/en-us/library/ms615518.aspx的“备注”部分。

于 2011-05-03T02:32:36.440 回答
0

在 Silverlight 中,在导航到该页面之前会发生一个事件“OnNavigatedFom”。希望 WPF 也可能相同。

protected override void OnNavigatedFrom(NavigationEventArgs e) {
    base.OnNavigatedFrom(e);
}
于 2011-05-24T15:50:14.387 回答