如何在 maham 中创建对话结果?
How to create a dialog result in maham?
我正在尝试创建一个代码来显示对话结果:
var result = this.ShowMessageAsync("proceed?", "Info", MessageDialogStyle.AffirmativeAndNegative);
if (result == MessageDialogResult.Affirmative)
{
this.Hide();
}
但是这一行的编译器 if (result == MessageDialogResult.Affirmative)
,向我显示此消息:
you can not apply the == operator to operands of type 'Task ' and 'MessageDialogResult'
在一些例子中使用了这个运算符,我做错了什么?
ShowMessageAsync()
似乎是一种异步方法,这意味着它 returns 是 Task<T>
而不是 T
.
所以你可以await
这样的任务:
var result = await this.ShowMessageAsync("proceed?", "Info", MessageDialogStyle.AffirmativeAndNegative);
或者你可以得到它的 Result
:
var result = this.ShowMessageAsync("proceed?", "Info", MessageDialogStyle.AffirmativeAndNegative)
.Result;
并不是说如果你想await
这个任务,你必须在一个标记为async
的方法中
我正在尝试创建一个代码来显示对话结果:
var result = this.ShowMessageAsync("proceed?", "Info", MessageDialogStyle.AffirmativeAndNegative);
if (result == MessageDialogResult.Affirmative)
{
this.Hide();
}
但是这一行的编译器 if (result == MessageDialogResult.Affirmative)
,向我显示此消息:
you can not apply the == operator to operands of type 'Task ' and 'MessageDialogResult'
在一些例子中使用了这个运算符,我做错了什么?
ShowMessageAsync()
似乎是一种异步方法,这意味着它 returns 是 Task<T>
而不是 T
.
所以你可以await
这样的任务:
var result = await this.ShowMessageAsync("proceed?", "Info", MessageDialogStyle.AffirmativeAndNegative);
或者你可以得到它的 Result
:
var result = this.ShowMessageAsync("proceed?", "Info", MessageDialogStyle.AffirmativeAndNegative)
.Result;
并不是说如果你想await
这个任务,你必须在一个标记为async