C# wpf 中的确认框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18315786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Confirmation Box in C# wpf
提问by user2622971
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?
我想在 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");
}
}
}
采纳答案by Habib
Instead of using WinForm MessageBox, use the MessageBoxprovided by WPF and later use MessageBoxResult
instead of DialogResult
in WPF.
不使用 WinForm MessageBox,而是使用WPF 提供的MessageBox,稍后使用MessageBoxResult
而不是DialogResult
在 WPF 中使用。
like:
喜欢:
MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);
if (messageBoxResult == MessageBoxResult.Yes)
//...........