Question

I used MessageBox in that manner:

Deployment.Current.Dispatcher.BeginInvoke(() => {

                MessageBox.Show("The alarm has been raised");
            });

How to take an action after user taps ok?

Was it helpful?

Solution 2

Add reference of Microsoft.Xna.Framework.GamerServices in your project.

Deployment.Current.Dispatcher.BeginInvoke(() => {
            List<string> messageboxitm = new List<string>();
            messageboxitm.Add("Yes");
            messageboxitm.Add("No");
            IAsyncResult result = Guide.BeginShowMessageBox("Message", "The alarm has been raised", messageboxitm, 0, MessageBoxIcon.Alert, new AsyncCallback(OnMessageBoxClosed), null);

});
 private void OnMessageBoxClosed(IAsyncResult ar)
        {
            int? buttonIndex = Guide.EndShowMessageBox(ar);
            switch (buttonIndex)
            {
                case 0:
                   //Do your work
                    break;               
                default:
                    break;
            }
        }

OTHER TIPS

In simple situations you can use MessageBoxResult (under Windows Phone limited only to Buttons OK / OKCancel):

Deployment.Current.Dispatcher.BeginInvoke(() =>
{
   MessageBoxResult result = MessageBox.Show("Show next message?", "Question", MessageBoxButton.OKCancel);
   // code after user click
   if (result == MessageBoxResult.OK) MessageBox.Show("Yeah");
});

But it is little limited and you cannot change buttons content. Your solution using Guide.BeginShowMessageBox is more configurable. You can also use other solutions: CustomMessageBox from Windows Phone Toolkit and if you have Telerik - RadMessageBox.

        IAsyncResult result =Microsoft.Xna.Framework.GamerServices.Guide.BeginShowMessageBox(
"Info",
"Alarm has been raised",
new string[] { "OK", "Call emergency" },
0,
Microsoft.Xna.Framework.GamerServices.MessageBoxIcon.None,
null,
null);

       result.AsyncWaitHandle.WaitOne();
        media.AutoPlay = true;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top