I need some info. I got a login function called after clicking on the login button. At the beginning of the async function, I set IsBusy=true, then I call my await LoginAsynx(user, pass) function. The loading indicator does not pop. So I try to add a await Task.Delay(100); just after IsBusy=true and before the login function and now the loading animation work.
I am new to xamarin.form, so I don't understand why this behaviour occurred. Like if the await function came to fast and lock the UI thread before the IsBusy=true complete the binding.
EDIT 1 Command calling the fucntion:
public ICommand SignInCommand => new Command(async () => await SignInAsync());
here my LoginViewModel
private async Task SignInAsync()
{
IsBusy = true;
await Task.Delay(100); // If I remove that, no more wating indicator
bool isValid = Validate();
if (isValid)
{
try
{
KelvinLoginResult LoginResult = await _kelvinService.LoginAsync(UserName.Value, Password.Value);
if (LoginResult.EstAuthtifie == false)
{
await DialogService.ShowAlertAsync("Authentication error", "Authentication error", "Ok");
}
else
{
await NavigationService.NavigateToAsync<MainViewModel>();
//await NavigationService.RemoveLastFromBackStackAsync();
}
}
catch (Exception ex)
{
await DialogService.ShowAlertAsync(ex.Message, "Error", "Ok");
}
}
IsBusy = false;
}
Edit 2: Activity indicator on the form
<!-- INDICATOR -->
<ActivityIndicator
Color="{StaticResource LightGreenColor}"
IsRunning="{Binding IsBusy}"
IsVisible="{Binding IsBusy}"
VerticalOptions="Center"
HorizontalOptions="Center">
<ActivityIndicator.WidthRequest>
<OnPlatform x:TypeArguments="x:Double">
<On Platform="iOS, Android" Value="100" />
<On Platform="UWP, WinRT, WinPhone" Value="400" />
</OnPlatform>
</ActivityIndicator.WidthRequest>
</ActivityIndicator>
Edit 3
public bool IsBusy
{
get
{
return _isBusy;
}
set
{
_isBusy = value;
RaisePropertyChanged(() => IsBusy);
}
}