在WPF中是否有一个标准的消息框,如WinForms的System.Windows.Forms.MessageBox.Show(),或者我应该使用WinForms消息框?
当前回答
也许下面的代码会有所帮助:
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。它有一个非常相似的接口,但是使用其他枚举来表示参数和返回值。
WPF中与WinForms的MessageBox等价的是System.Windows.MessageBox。
正如其他人所说,在WPF命名空间(System.Windows)中有一个MessageBox。
问题是,它是相同的旧消息框与确定,取消等。Windows Vista和Windows 7转而使用任务对话框。
不幸的是,任务对话框没有简单的标准界面。我使用来自CodeProject KB的实现。
在WPF中,这段代码,
System.Windows.Forms.MessageBox.Show("Test");
替换为:
System.Windows.MessageBox.Show("Test");
也许下面的代码会有所帮助:
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();
}
}
}
推荐文章
- c#线程安全快速(est)计数器
- 如何将此foreach代码转换为Parallel.ForEach?
- 如何分裂()一个分隔字符串到一个列表<字符串>
- 如何转换列表<字符串>列表<int>?
- c#对象列表,我如何得到一个属性的和
- 我如何使用IValidatableObject?
- 如何指定最小值,但没有使用范围数据注释属性的最大小数?
- c# vs Java Enum(适合c#新手)
- c#消毒文件名
- 禁用Visual Studio 2015额外调试选项
- 在EF中更新父实体时如何添加/更新子实体
- ASP。NET身份的默认密码散列器-它是如何工作的,它是安全的?
- 如何写一个JSON文件在c# ?
- 静态隐式运算符
- 不区分大小写列表搜索