【问题标题】:Confirmation Box in C# wpf [duplicate]C# wpf中的确认框[重复]
【发布时间】:2013-08-19 14:03:23
【问题描述】:

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

        }
    }

【问题讨论】:

    标签: c# wpf right-click confirm


    【解决方案1】:

    不使用 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)
     //...........
    

    【讨论】:

    • @user1130886 感谢编辑
    • 以及如何使用它?
    • 编辑你的例子,有不同的类型,编辑DialogResult messageBoxResult = ...MessageBoxResult messageBoxResult = ...或者相反,在if子句中应该是if (messageBoxResult == MessageBoxResult.Yes)
    • @vinsa,感谢您指出。不知何故,它被错误地编辑了,并且该编辑也被批准了。我已经回滚了编辑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    • 2016-09-20
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多