2011-07-18 32 views
6

Làm cách nào để tạo hộp thoại xác nhận trong cửa sổ điện thoại 7?cách tạo hộp thoại xác nhận trong cửa sổ điện thoại 7?

Tôi có một ứng dụng mà tôi có thể xóa các mục, nhưng khi ai đó nhấp delete, tôi muốn làm cho anh ấy một hộp thoại xác nhận nơi họ có thể bấm vào 'xác nhận' hoặc 'hủy bỏ'

Làm thế nào tôi có thể làm điều này?

+2

thể trùng lặp của [WP7 Alert thoại] (http://stackoverflow.com/questions/ 4475602/wp7-alert-dialog) –

Trả lời

4

Đâ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.

0

Nếu OK/Cancel là đủ tốt cho bạn, bạn có thể dính vào MessageBox.Show thường xuyên

1

Thay vì yêu cầu người dùng xác nhận xóa, có bạn coi cho người sử dụng khả năng "un-delete" mặt hàng?

Trong khi điều này có thể là một chút công việc, khi nó có ý nghĩa trong bối cảnh của ứng dụng nó có thể dẫn đến một trải nghiệm người dùng tốt hơn nhiều.

26

bạn có thể sử dụng này:

if(MessageBox.Show("Are you sure?","Delete Item", MessageBoxButton.OKCancel) == MessageBoxResult.OK) 
{ 
//Delete Sentences 
} 

Hiển thị một cái gì đó hộp thoại như thế này:

enter image description here

Các vấn đề liên quan