amnk
amnk

Reputation: 78

Xamarin button text change in code behind

Here my code sample

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

This is code behind

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

i want to know how to change button text when click button. i want to do this Code behind

Upvotes: 0

Views: 952

Answers (1)

Jason
Jason

Reputation: 89214

assign a name to your button

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

then in the code behind:

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

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

Upvotes: 1

Related Questions