在WPF中是否有一个标准的消息框,如WinForms的System.Windows.Forms.MessageBox.Show(),或者我应该使用WinForms消息框?


当前回答

WPF中与WinForms的MessageBox等价的是System.Windows.MessageBox。

其他回答

WPF中与WinForms的MessageBox等价的是System.Windows.MessageBox。

在WPF中,这段代码,

System.Windows.Forms.MessageBox.Show("Test");

替换为:

System.Windows.MessageBox.Show("Test");

WPF的等效程序是System.Windows.MessageBox。它有一个非常相似的接口,但是使用其他枚举来表示参数和返回值。

也许下面的代码会有所帮助:

using Windows.UI.Popups;
namespace something.MyViewModels
{
    public class TestViewModel
    {
        public void aRandonMethode()
        {
            MyMessageBox("aRandomMessage");
        }

        public async void MyMessageBox(string mytext)
        {
            var dialog = new MessageDialog(mytext);
            await dialog.ShowAsync();
        }
    }
}

正如其他人所说,在WPF命名空间(System.Windows)中有一个MessageBox。

问题是,它是相同的旧消息框与确定,取消等。Windows Vista和Windows 7转而使用任务对话框。

不幸的是,任务对话框没有简单的标准界面。我使用来自CodeProject KB的实现。