How do I know if a button was clicked? Xamarin Forms

1

I have sometimes needed to know when a button has been clicked and I have not found a native property in C # / Xamarin. For example:

InthisimageabovewehaveaEntrywithaText(justtoillustrate)writtenPesquisa...byDefautandwithaToUpperfunction(toleavealltextincapitalletter),ifincaseIclickthebuttonLIMPARIalreadywantedtobeabletoaddthetextPesquisa...again,buttheToUpperfunctionforcesthetexttobePESQUISA....SoIthoughtI'dmakeaifthatwoulddothefollowing:

if(BotãoLimparPressionado=true){EntryPesquisar="Pesquisa..."
}
else    //a função para os outros casos continuariam normais
{
   EntryPesquisar.ToUpper
}
    
asked by anonymous 10.07.2018 / 16:15

1 answer

2

Assuming you are developing the visual via XAML ...

In your XAML use

<Button Clicked="OnClick">Button</Button>

And in your codebehind

private bool BotaoClicado = false;

public void OnClick(object sender, EventArgs args)
{
  BotaoClicado = true;
  // Aqui dentro você poem sua programação
}

private void OutroMetodo()
{
  if(BotaoClicado)
  {
    //Aqui você poem o que deve ser feito
  }
}
    
10.07.2018 / 16:23