After Windows Phone App comes back from Tombstone App.RootFrame.Navigate(uri) doesn't work
I have an app that works just fine. But if I launch launch any one of the tasks (WebBrowserTask, SendEmailTask etc) I get tombstoned. When I finished the task the App restores just fine but the Navigate() calls don't work anymore. Meaning that the code runs but nothing happens, all navigation is broken from then on.
Here's the code I use开发者_开发知识库 to navigate:
((App)App.Current).RootFrame.Navigate(new Uri("/MyPage.xaml", UriKind.Relative));
I'm handling the NavigationFailed event as well and that never gets fired...
((App)App.Current).RootFrame.NavigationFailed += RootFrame_NavigationFailed;
Is this the same issue reported in ApplicationBar icon button click event not fired after a PhotoChooserTask?
If so, the issue may due to trying to navigate before the application has been fully reconstructed.
You may be able to address this by forcing the navigation onto the UI thread. (see linked question.)
Also,
Is there a reason you're calling Navigate
directly on the RootFrame and not using NavigationService
?
Can you reproduce this problem in an empty project?
If not, there may be something else in your app which is causing this.
While I didn't end up finding the root cause exactly I found how to get out of the situation. It looks like when the Application comes back from a another task the "Application.Activated" fires. After like 3 hours of debugging I found that if you set the Application.RootVisual in this method navigation works again. In the debugger the RootVisual is a frame but it looks like it was the wrong one - not sure how that could ever happen (any guidance welcome). So when I was calling .Navigate(uri) it probably was navigating, just not in the right frame.
Hope this helps someone else...
精彩评论