Windows Phone - OnNavigatingFrom - problem
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开发者_JAVA技巧 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.
I believe that you need to add an event that captures the transition completion. Check out the demo that Microsoft provides for a list view application.
The approach you are taking is not quite correct. Instead it is better to alter the page frame to know how to do transitions between pages. You can see a good examples of this on a Channel 9 vid or on Avi Pilosof's blog.
Example:
<ControlTemplate x:Key="TransitioningFrame" TargetType="navigation:PhoneApplicationFrame">
<Border>
<toolkit:TransitioningContentControl
Content="{TemplateBinding Content}" Transition="DownTransition" />
</Border>
</ControlTemplate>
I am baffled why we need to roll our own smooth transitions for WinPhone7, but there it is. Jeff Brand (SlickThought.net) seems to have the best solution so far. Here is a nice article with a walkthrough video and sample code, though his sample code in the article was for the April CTP and appears to be broken in the Beta tools.
精彩评论