user1094497
user1094497

Reputation: 1

Back Button in WP

I’m facing a problem in an application that I’m building for windows phone. The application consists of many pages and when the back button is pressed in one of the pages it goes back to the main page. The problem is that when the back button is pressed again in the main page it goes to the previous page and it doesn’t exit the application. How would i exit the application?

Upvotes: 0

Views: 436

Answers (2)

Đorđe Relić
Đorđe Relić

Reputation: 428

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
        NavigationService.GoBack(); // if you want to go back   

        // or if you want to exit
        try
        {
            while(NavigationService.CanGoBack)
                NavigationService.RemoveBackEntry();
        }
        catch (InvalidOperationException)
        {
        }
 }

Upvotes: 0

Pol
Pol

Reputation: 5134

Don't override back button behavior. If user presses back, he want to go to previous page. If you have another back button in UI then use NavigationService.GoBack instead of going to concrete page.

If your app really can't work this way and you cannot change this, as a last resort you can remove last entry from navigation history (so back will not go to this entry) using NavigationService.RemoveBackEntry (this is new in Mango).

Upvotes: 1

Related Questions