2

I am navigating to other page after button onClick(). I want to avoid situation with double click. Now when I click button more than once, for example twice, before the next page is shown with the result, there are multiple instances of the next page created.

private async void Button_Clicked(object sender, EventArgs e)
{
    var newPage = new NewPage();
    await Navigation.PushAsync(newPage);
}

What should i need to be added in my code?

DawidJ
  • 1,239
  • 12
  • 19
  • 2
    disable button on click.. and enable it again after other page gets loded – V-rund Puro-hit Jan 22 '19 at 11:11
  • Possible duplicate of [How to truly avoid multiple buttons being clicked at the same time in Xamarin.Forms?](https://stackoverflow.com/questions/49986982/how-to-truly-avoid-multiple-buttons-being-clicked-at-the-same-time-in-xamarin-fo) – FreakyAli Jan 22 '19 at 12:24

1 Answers1

1

You could judge istapped when button is tapped like following code.

var _istapped = false;

private async void Button_Clicked(object sender, EventArgs e)
{
    if(_istapped)
        return;

    _istapped = true;

    var newPage = new NewPage();
    await Navigation.PushAsync(newPage);

    _istapped = false;
}
Leon Lu - MSFT
  • 8,163
  • 2
  • 5
  • 42