Reputation: 586
I'm trying to create a code to show a dialog result:
var result = this.ShowMessageAsync("proceed?", "Info", MessageDialogStyle.AffirmativeAndNegative);
if (result == MessageDialogResult.Affirmative)
{
this.Hide();
}
but the compiler on this line if (result == MessageDialogResult.Affirmative)
, show me this message:
you can not apply the == operator to operands of type 'Task ' and 'MessageDialogResult'
In some example it was used this operator, what I doing wrong?
Upvotes: 0
Views: 698
Reputation: 24395
ShowMessageAsync()
seems to be an asyncronous method, meaning it returns a Task<T>
instead of a T
.
So you can either await
the task like this:
var result = await this.ShowMessageAsync("proceed?", "Info", MessageDialogStyle.AffirmativeAndNegative);
Or you can get the Result
of it:
var result = this.ShowMessageAsync("proceed?", "Info", MessageDialogStyle.AffirmativeAndNegative)
.Result;
Not that if you want to await
the task, you must be in a method marked async
Upvotes: 1