Windows Phone - OnNavigatingFrom - problem
Posted
by Martin Anderson
on Stack Overflow
See other posts from Stack Overflow
or by Martin Anderson
Published on 2010-03-21T09:25:00Z
Indexed on
2010/03/21
9:31 UTC
Read the original article
Hit count: 399
I believe this is just a problem for me, due to my lack of programming ability. I am currently exploring transitions between page navigation with Windows Phone apps. I was originally using storyboards, and completed event handlers to have my pages animate on and off screen. These leads to the a problem when you want to navigate to many pages from one page, using the same transition.
So I have started looking at OnNavigatedTo, and OnNavigatingFrom events and while it is working nicely for OnNavigatedTo, the later just wont work. It seems the Microsoft.Phone.Navigation assembly does not contain OnNavigatingFrom, and referencing System.Windows.Navigation, compiles ok, but I cant get pages to animate off upon navigation.
I have a button on my Page2, which I want to go back to my MainPage (after I over-rided the back key with a message box for testing). I have transitions made on the page, and I have this as the event handler code...
private void btnP2_BackToP1Clicked(object sender, System.Windows.RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
With this code for the OnNavigatedTo and OnNavigatingFrom events...
protected override void OnNavigatedTo(PhoneNavigationEventArgs e)
{
PageTransition_In.Begin();
}
// //
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
PageTransition_Out.Begin();
base.OnNavigatingFrom(e);
}
I have the feeling that OnNavigatingFrom may not(yet) be supported for Windows Phone Apps. OnNavigatedFrom is part of Microsoft.Phone.Navigation, but it only performs actions once the page is no longer active, which is too late to perform any animation effects.
© Stack Overflow or respective owner