在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的实现。
推荐文章
- 防止在ASP中缓存。NET MVC中使用属性的特定操作
- 转换为值类型'Int32'失败,因为物化值为空
- c#中有任何连接字符串解析器吗?
- 在Linq中转换int到字符串到实体的问题
- 是否可以动态编译和执行c#代码片段?
- 创建自定义MSBuild任务时,如何从c#代码获取当前项目目录?
- c#和Java的主要区别是什么?
- 在c#中创建一个特定时区的DateTime
- .NET中的属性是什么?
- csproj文件中的“Service Include”是干什么用的?
- 如何使用try catch进行异常处理是最佳实践
- 替换字符串中第一次出现的模式
- .NET中字节的字面后缀?
- 如何处理AccessViolationException
- c#忽略证书错误?