Jieqin
Jieqin

Reputation: 588

How To Close MessageBox Programmatically in WP8?

I'm aware that there are already questions questions asked regarding closing a MessageBox programmatically . But the solution to those questions is to use a timer.

I am trying to develop an NFC application, so when i create a MessageBox, it contains a message Please Tap Your NFC. So technically, the Timer isn't helpful. I need a way to close or dispose a MessageBox.

Please advice.

Upvotes: 4

Views: 841

Answers (2)

sumit gupta
sumit gupta

Reputation: 79

From lieska at MessageBox.Show in App Closing/Deactivated events

Register BackKeyPress event on RootFrame.

RootFrame.BackKeyPress += BackKeyPressed;
private void BackKeyPressed(object sender, CancelEventArgs e)
    {
        var result = (MessageBox.Show("Do you want to exit XXXXX?", "Application Closing", MessageBoxButton.OKCancel));
        if (result == MessageBoxResult.Cancel)
        {
            // Cancel default navigation
            e.Cancel = true;
        }
}

Upvotes: 0

Alaa Masoud
Alaa Masoud

Reputation: 7135

You can create a custom window yourself as described in the question you linked. However, instead of a timer you can and include a Hide method which you can call once NFC connection event occurs.

Alternatively, you could get Coding4Fun toolkit and use MessagePrompt class which already includes a Hide method.

Upvotes: 3

Related Questions