这是处理Xamarin Forms中响应的正确方法吗?

时间:2017-07-04 09:50:51

标签: xamarin xamarin.forms

var response = await App.PhrasespageCS.DisplayAlert("Reset score",
     "You have more than 50 points. Are you sure you want to reset it to 0?",
     "Yes", "No");

if (response == true)
{
    App.DB.ResetPointsForSelectedPhrase(App.cfs);
}

我不清楚在这里使用等待,并希望得到建议。这也可以合并成一个陈述吗?

2 个答案:

答案 0 :(得分:1)

Await意味着该应用已经为您创建了一个对话框,并且会等到答案得到回应。 这是写它的正确方法。此外,如果你想减少代码,你可以把它,如下,

if (await App.PhrasespageCS.DisplayAlert("Reset score", "You have more than 50 points.Are you sure you want to reset it to 0 ? ", "Yes", "No"))
            App.DB.ResetPointsForSelectedPhrase(App.cfs);

答案 1 :(得分:0)

example中所述,您应该使用等待。另请检查this。您的目的代码在上面的答案中给出。