Confirmation Box in C# wpf

c#, confirm, right-click, wpf

Solution

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)
 //...........

Problem

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"); } } } ```

Original source

Related problems