Xamarin按钮文本后面的代码更改

时间:2017-07-05 16:04:15

标签: xamarin

这是我的代码示例

  <controls:SwitchboardButton Grid.Row="0"   Grid.Column="0" Label="Test">
    <controls:SwitchboardButton.GestureRecognizers>
      <TapGestureRecognizer   Tapped="CameraButtonTapped" />
    </controls:SwitchboardButton.GestureRecognizers>
  </controls:SwitchboardButton>

这是背后的代码

    public async void CameraButtonTapped(object sender, EventArgs args)
    {
        await Navigation.PushAsync(new TensePage());
    }

我想知道如何在点击按钮时更改按钮文字。我想做这个代码背后的

1 个答案:

答案 0 :(得分:1)

为按钮指定名称

<controls:SwitchboardButton x:Name="btnSwitch" Grid.Row="0"   Grid.Column="0" Label="Test">

然后在后面的代码中:

public async void CameraButtonTapped(object sender, EventArgs args)
{
    btnSwitch.Text = "Some New Text";

    await Navigation.PushAsync(new TensePage());
}