How to create a confirmation dialog in a Windows 7 phone?

How to create a confirmation dialog in Windows Phone 7?

I have an application in which I can delete items, but when someone clicks on the delete, I want him to get a confirmation dialog where they can click “confirm” or “abort”

How can i do this?

+6
source share
4 answers

Here is the method I use. By the way, for better user convenience and consistency, use the words “delete” and “cancel” rather than “confirm” or “cancel”.

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; } 

You will need to add a link to Microsoft.Xna.Framework.GamerServices in your project.

+4
source

you can use this:

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

Shows a dialog like this:

enter image description here

+26
source

Instead of asking the user to confirm the deletion, have you considered giving the user the option to “delete” items?

Although this may be a little more work when it makes sense in the context of the application, it can lead to a significantly better user experience.

+1
source

If OK / Cancel is enough for you, you can stick with the usual MessageBox.Show

0
source

Source: https://habr.com/ru/post/892981/


All Articles