39

我想在 C# 代码中显示确认框。我已经看到了上面的解决方案,但它向我显示了“是”的异常,因为“System.Nullable”不包含“是”的定义。我应该如何消除这个错误?

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

        }
    }
4

1 回答 1

137

不使用WinForm MessageBox,而是使用WPF提供的MessageBox,以后在WPF中使用MessageBoxResult代替DialogResult

喜欢:

MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
        if (messageBoxResult == MessageBoxResult.Yes)
 //...........
于 2013-08-19T14:05:34.623 回答