2

I have a button with an

await this.Navigation.PushModalAsync

The command runs on click. I want to show the ActivityIndicator on a press, this is my button clicked command:

async void ButtonClicked(object sender, EventArgs e)
{
    actCentros.IsRunning = true;
    await this.Navigation.PushModalAsync(...);
    actCentros.IsRunning = false;
}

This takes about 1 second to appear. Without the PushModalAsync it appears on click.

Why does it happen?

R15
  • 13,982
  • 14
  • 97
  • 173
doxsi
  • 1,002
  • 19
  • 42
  • 1
    This is not enough code, but from what i can see, your button press is an async method, where any UI related changes have to be invoked on MainThread. ActivityIndicator has to be invoked on UI thread. I assume the reason why you have that slight delay is, because your code is waiting to execute what is inside the method once that is finished, thats when ActivityIndicator shows. – Woj Apr 03 '19 at 11:42
  • Tx. Have you any solution for that? – doxsi Apr 03 '19 at 12:21
  • Animation is the trick, as explained on this [solution](https://stackoverflow.com/questions/38568703/show-activityindicator-when-pushing-new-page-to-navigation) – doxsi Apr 03 '19 at 14:12
  • Can you add enough code to reproduce this problem? – nevermore Apr 04 '19 at 05:59

1 Answers1

0

What I have found to work is to bind the IsRunning property of the Activity Indicator to a Boolean INotifyPropertyChanged based property on your ViewModel, such as 'IsProcessing', and setting this to true at the start of the Command's Execute delegate method, and back to false at the end of the method. I do not notice any delay in this approach from clicking the button bound to the Command.

Lindsay
  • 575
  • 8
  • 18