arachide
arachide

Reputation: 8076

prompt confirmation dialog when exit app

I am working on an app on wp7.

I hope to prompt a confirmation dialog when user exit app (press back button).

Is it possible?

Welcome any comment

Upvotes: 2

Views: 5258

Answers (3)

Ku6opr
Ku6opr

Reputation: 8126

You can stop back navigation by set e.Cancel in back key press event.

In MainPage.xaml.cs constructor:

OnBackKeyPress += (s, e) =>
{
    if (MessageBox.Show("", "", MessageBoxButtons.OkCancel) == MessageBoxButtons.Cancel)
    {
        e.Cancel = true;
    };
};

Upvotes: 1

Santhu
Santhu

Reputation: 1525

Please handle the BackKeyPress button in the Application page to handle the back key press.

In Page.xaml file in the element add this code

BackKeyPress="PhoneApplicationPage_BackKeyPress"

it should look like

<phone:PhoneApplicationPage BackKeyPress="PhoneApplicationPage_BackKeyPress"
..//other attributes .. >

in event handler you write the code as follows

private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
             MessageBoxResult mb =  MessageBox.Show("You want exit the page", "Alert", MessageBoxButton.OKCancel);

            if( mb != MessageBoxResult.OK)
            {
                e.Cancel = true;
            }

        }

Upvotes: 5

Paul Annetts
Paul Annetts

Reputation: 9604

It's possible to catch when the user exits pressing the Back button, but it is not possible to stop the application from being made "dormant" when the user presses the hardware Start button or Search buttons.

Upvotes: 1

Related Questions