2011-05-02 44 views
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 

回答

1

是的!嘗試Navigating事件。在請求導航時引發。有關NavigationServices事件的更多信息可在http://msdn.microsoft.com/en-us/library/ms615518.aspx的「備註」部分找到。

+0

喜奔。問題是,「導航」也只包含下一個而不是當前頁面。哦,該死的,我在線......我可以在這種情況下調用'?CType(sender,Frame).Source.ToString'。謝謝你的建議。 – goldengel 2011-05-03 18:13:46

+0

好的,試過了。對不起,但問題是,在任何情況下,Uri總是包含需要加載的url。我看不到當前或最後一個uri。 '?CType(發件人,框架).Source.ToString'不起作用。 – goldengel 2011-05-03 18:19:26

+0

嘗試將發件人轉換爲類型NavigationWindow,然後訪問CurrentSource屬性。 – 2011-05-03 22:11:02

0

在Silverlight中,有一個瀏覽該頁面之前發生的事件「OnNavigatedFom」 ..希望它可能是WPF相同以及..

protected override void OnNavigatedFrom(NavigationEventArgs e) { 
    base.OnNavigatedFrom(e); 
}