如何在单击按钮时调用方法并传递参数?

时间:2017-07-08 12:55:06

标签: c# xamarin

我这段代码:

        correctButton.Clicked += (sender, e) =>
        {
            App.DB.IncrementScore(AS.cfs, AS.phrase); 

            correctAns++;
            AS.pointsCount[(int)AS.cfs]++;
            scoreCountLabel.Text = FontAwesome.FAStop.Repeat(correctAns);
            Device.StartTimer(TimeSpan.FromSeconds(0.5), () =>
            {
                switch (AS.cardOrder)
                {
                    case CardOrder.FirstToLast:
                        AS.orderPhraseIndex++;
                        AS.phraseIndexList.Add(AS.orderPhraseIndex);
                        getPhraseFirstToLast();
                        break;
                    case CardOrder.Random:
                        getRandomNumber();
                        getRandomPhrase();
                        break;
                }
                return false;
            });
        };

我想将运行的代码移到方法中并传递参数。但是如何在单击correctButton时调用该方法?

1 个答案:

答案 0 :(得分:2)

correctButton.Clicked += correctButtonClicked;

protected void correctButtonClicked(object sender, EventArgs e)
{
  // code goes here
}