Is there a "Before" Navigated event?
Im using WPF with Navigation Service. I need to catch a situation before the next page is navigated. Is thera any event "before" next page is navigated?
Navigate("MyPage1.xaml")
Navigate("MyPage2.xaml")'now, I need a event which shows me : FromPage("MyPage1.xaml") before navigating to "MyPage2.xaml".
code sample
Private Sub Window_Loaded(ByVal sender As System.Object, B开发者_如何学JAVAyVal 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
Yes! Try the Navigating event. It is raised when a navigation is requested. More information on NavigationServices events is found in the "Remarks" section of http://msdn.microsoft.com/en-us/library/ms615518.aspx.
In Silverlight, there is an event "OnNavigatedFom" that occurs before navigating to that page.. Hope it might be the same for WPF as well..
protected override void OnNavigatedFrom(NavigationEventArgs e) {
base.OnNavigatedFrom(e);
}
精彩评论