I'm having quite some trouble implementing a functionality as simple as showing an ActivityIndicator while a page is loading, it's been proving very difficult.
This is the code I'm using on App.xaml.cs:
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new LoginPage());
}
}
And this is my LoginPage
public partial class LoginPage : ContentPage
{
public LoginPage()
{
InitializeComponent();
btnLogin.Clicked += BtnLogin_Clicked;
}
protected async void BtnLogin_Clicked(object sender, EventArgs e)
{
loadingView.IsVisible = true;
activityIndicator.IsRunning = true;
await Navigation.PushAsync(new SchedulePage());
loadingView.IsVisible = false;
activityIndicator.IsRunning = false;
}
}
Without getting into much detail, the loadingView is a view I have on the xaml file, which houses my ActivityIndicator. My main problem here is that when I call Navigation.PushAsync(), the animation of the ActivityIndicator is halted. According to what I've read this happens because both operations happen on the Main thread, so one interrupts the other.
The reason I need to show the indicator, is because my SchedulePage takes a lot of time to render, since it has an XLabs calendar control.
How would you go about implementing something like this?