Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirmation Box in C# wpf [duplicate]

I want to show confirmation Box in C# code. I've seen above solution for that but it shows me exception at 'Yes' as 'System.Nullable' does not contain definition for 'Yes'. How should I remove this error?

 private void listBox1_MouseRightButtonDown(object sender, MouseButtonEventArgs e)     {         if (sender is ListBoxItem)         {             ListBoxItem item = (ListBoxItem)sender;             Harvest_TimeSheetEntry entryToDelete = (Harvest_TimeSheetEntry)item.DataContext;              DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("Are you sure?", "Delete Confirmation", MessageBoxButtons.YesNo);              if (dialogResult == DialogResult.Yes)  // error is here             {                 Globals._globalController.harvestManager.deleteHarvestEntry(entryToDelete);             }             else             {                 System.Windows.MessageBox.Show("Delete operation Terminated");             }          }     } 
like image 563
user2622971 Avatar asked Aug 19 '13 14:08

user2622971


People also ask

What is the purpose of the confirm dialogue box?

A confirm box is often used if you want the user to verify or accept something. A confirm box takes the focus away from the current window, and forces the user to read the message.

How use confirm box in asp net code behind?

Solution 4createElement("INPUT"); confirm_value. type = "hidden"; confirm_value.name = "confirm_value"; if (confirm("Do you want to save data?")) { confirm_value. value = "Yes"; } else { confirm_value. value = "No"; } document.


1 Answers

Instead of using WinForm MessageBox, use the MessageBox provided by WPF and later use MessageBoxResult instead of DialogResult in WPF.

like:

MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);         if (messageBoxResult == MessageBoxResult.Yes)  //........... 
like image 61
Habib Avatar answered Sep 26 '22 01:09

Habib