windows-phone-7 – 如何在Windows Phone 7中创建确认对话框?

前端之家收集整理的这篇文章主要介绍了windows-phone-7 – 如何在Windows Phone 7中创建确认对话框?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在 Windows Phone 7中创建确认对话框?

我有一个应用程序,我可以删除项目,但当有人点击删除,我想让他一个确认对话框,他们可以点击’确认’或’中止’

我怎么能这样做?

这是我使用的方法.为了获得更好的用户体验和一致性,请考虑使用“删除”和“取消”而不是“确认”或“中止”.
  1. public static MessagePromptResult Show(string messageBoxText,string caption,string button1,string button2)
  2. {
  3. int? returned = null;
  4. using (var mre = new System.Threading.ManualResetEvent(false))
  5. {
  6. string[] buttons;
  7. if (button2 == null)
  8. buttons = new string[] { button1 };
  9. else
  10. buttons = new string[] { button1,button2 };
  11.  
  12. Microsoft.Xna.Framework.GamerServices.Guide.BeginShowMessageBox(
  13. caption,messageBoxText,buttons,// can choose which button has the focus
  14. Microsoft.Xna.Framework.GamerServices.MessageBoxIcon.None,// can play sounds
  15. result =>
  16. {
  17. returned = Microsoft.Xna.Framework.GamerServices.Guide.EndShowMessageBox(result);
  18. mre.Set(); // could have done it all without blocking
  19. },null);
  20.  
  21. mre.WaitOne();
  22. }
  23.  
  24. if (!returned.HasValue)
  25. return MessagePromptResult.None;
  26. else if (returned == 0)
  27. return MessagePromptResult.Button1;
  28. else if (returned == 1)
  29. return MessagePromptResult.Button2;
  30. else
  31. return MessagePromptResult.None;
  32. }

您需要将Microsoft.Xna.Framework.GamerServices的引用添加到您的项目中.

猜你在找的Windows相关文章