Jonathan Allen
Jonathan Allen

Reputation: 70277

Custom message boxes in WP7

I really like the look/behavior of window created by MessageBox.Show. How can I create one from scratch so that I can add other stuff like a textbox?

Upvotes: 1

Views: 3716

Answers (5)

ingh.am
ingh.am

Reputation: 26742

Add references to Microsoft.Xna.Framework and Microsoft.Xna.Framework.GamerServices and then you can do the following:

Guide.BeginShowMessageBox("Title",
                          "Text",
                          new List<String> { "Answer 1", "Answer 2" },
                          0, // Focus button
                          MessageBoxIcon.Alert,
                          asyncResult =>
                          {
                              int? response = Guide.EndShowMessageBox(asyncResult);
                              if(response == null)
                              {
                                  // Back button pressed
                              }
                              else if(response == 0)
                              {
                                  // "Answer 1" pressed
                              }
                              else if(response == 1)
                              {
                                  // "Answer 2" pressed
                              }
                          },
                          null);

I have tested this with Windows Phone 7 and it appears to work.

Upvotes: 0

Shawn Kendrot
Shawn Kendrot

Reputation: 12465

Take a look at this custom implementation. Looks and behaves just like the out of the box MessageBox and is easy to use. I've used it in two of my phone apps.

Upvotes: 0

Nicolas Lau
Nicolas Lau

Reputation: 1

In Mix11, Laurent Bugnion talked about Mvvm. In hist samples, there is a sample including the implement of Custom MessageBox. u can download the sourcecode from here and check the "03 JsonDemo - WP7 DialogService " sample.

Hope this help u.

Upvotes: 0

Divya
Divya

Reputation: 2622

Instead of using a MessageBox, you could try using a Popup.

But, you'll have to manually disable the contols on the screen when the popup is open (MessageBox does this automatically for you). Also, you'll have to override the back button behaviour so that back button closes the Popup if it is open. This is also automatically done by a MessageBox.

Upvotes: 2

keyboardP
keyboardP

Reputation: 69362

There's a good article here on creating your own version, which is now on CodePlex. There various customizable MessageBoxes in the Coding4Fun toolkit. If you want to do it all on your own, this guide might help as well.

Upvotes: 3

Related Questions