Đây là phương pháp tôi sử dụng. Bằng cách này cho một trải nghiệm người dùng tốt hơn và cho sự nhất quán vì lợi ích xem xét việc sử dụng các từ "xóa" và "hủy bỏ" thay vì "xác nhận" hoặc "hủy bỏ".
public static MessagePromptResult Show(string messageBoxText, string caption, string button1, string button2)
{
int? returned = null;
using (var mre = new System.Threading.ManualResetEvent(false))
{
string[] buttons;
if (button2 == null)
buttons = new string[] { button1 };
else
buttons = new string[] { button1, button2 };
Microsoft.Xna.Framework.GamerServices.Guide.BeginShowMessageBox(
caption,
messageBoxText,
buttons,
0, // can choose which button has the focus
Microsoft.Xna.Framework.GamerServices.MessageBoxIcon.None, // can play sounds
result =>
{
returned = Microsoft.Xna.Framework.GamerServices.Guide.EndShowMessageBox(result);
mre.Set(); // could have done it all without blocking
}, null);
mre.WaitOne();
}
if (!returned.HasValue)
return MessagePromptResult.None;
else if (returned == 0)
return MessagePromptResult.Button1;
else if (returned == 1)
return MessagePromptResult.Button2;
else
return MessagePromptResult.None;
}
Bạn sẽ cần thêm tham chiếu vào Microsoft.Xna.Framework.GamerServices vào dự án của bạn.
thể trùng lặp của [WP7 Alert thoại] (http://stackoverflow.com/questions/ 4475602/wp7-alert-dialog) –