Navigation in the application Activating Windows Phone 7 (Tombstoning)

Whenever my program is closed using overhead storage, when it is activated, I want the application to move back to the start screen.

I would like to do something like this

private void Application_Activated(object sender, ActivatedEventArgs e) { NavigationService.Navigate(new Uri("/Start.xaml", UriKind.Relative));
}

but that will not work. Thank you, Shureman.

+5
source share
5 answers

. , , , . , - , . , , , , .

, , .

. . Application_Activated , OnNavigatedTo, , . , , ( ) .


- , .

+5

, MSFT. WP7 , , .

, : NavigationService.GoBack() , . WP7 , , , . , NavigationCompleted, GoBack() , NavigationService.CanGoBack , :)

+2

, ,

private void Application_Activated(object sender, ActivatedEventArgs e)
{
    RootFrame.Navigated += RootFrame_Navigated;
}

void RootFrame_Navigated(object sender, NavigationEventArgs e)
{
    RootFrame.Navigated -= RootFrame_Navigated;
    RootFrame.Navigate(new Uri("/TestPage.xaml", UriKind.Relative));
}
+2

@Matt Lacey, , : , , :

5.2.3

Windows Phone , "" - . Windows Phone Launcher API- Chooser. 5.2.1.

, , , . , . Windows Phone.

? , , , .

0

, , tomstoning. , . - SplashPage.xaml. UriMapper :

    private void Application_Activated(object sender, ActivatedEventArgs e) {
        IsTombstoned = ! e.IsApplicationInstancePreserved;

        if (IsTombstoned) {
            //the os wants to return to the last page, but we want it to restart to our splash page 
            RootFrame.UriMapper = new RestartUriMapper();
        }
    }

SplashPage.xaml, , , ( ).

    protected override void OnNavigatedTo(NavigationEventArgs e) {
        base.OnNavigatedTo(e);

        if (NavigationContext.QueryString.ContainsKey("restart")) {
            var app = Application.Current as App;
            //a page redirect mapper was installed to get here from tombstone - reinstate the AssociationUriMapper now
            app.RootFrame.UriMapper = App.Root.AssociationUriMapper;

            //from tombstone, the last current nav source is still state, so force an initial navigation back to 
            //a new instance of this splash page and proceed start up from there
            App.PageNavigation.Navigate(@"/Pages/SplashPage.xaml?fromtomb=true");
        }
    }


class RestartUriMapper : UriMapperBase {
    Uri restartUri;

    public RestartUriMapper() {
        restartUri = new Uri(string.Format("/Pages/SplashPage.xaml?restart={0}", true.ToString()), UriKind.Relative);
    }

    public override Uri MapUri(Uri uri) {
        if (restartUri != null) {
            Uri nextPageUri = restartUri;
            restartUri = null;
            return nextPageUri;
        }

        return uri;
    }
}
0

All Articles