2011-05-02 39 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); 
}