WPF消息框显示错误信息

7

我正在开发一个WPF应用程序,我想显示带有信息或问题符号的消息框。我已经编写了以下代码:

MessageBox.Show("Added Sucessfully","Alert",MessageBoxImage.Information);

但它显示了一个错误/红线

错误:system.windows.messagebox.show(string,string,messageboximage)有一些无效的参数

2个回答

14

您错过了MessageBoxButton参数。请尝试以下操作:

MessageBox.Show("Added successfully", "Alert", MessageBoxButton.OK, MessageBoxImage.Information);

请确保您使用的是 System.Windows 命名空间中的 MessageBox,而不是 System.Windows.Forms


-1

你可以从消息框中获取结果并检查你的条件,如下:

MessageBoxResult result = MessageBox.Show("Added successfully", "Alert", MessageBoxButton.OK, MessageBoxImage.Information);
            if (result == MessageBoxResult.OK)
            {

            }

OP想要显示消息符号,而不是检查消息结果。此外,您代码的第一行与上面的答案相同。 - ElectricRouge

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接