After clicking the button, the next page is taking a little time to load. This is because the next page creates many dynamic label controls to show data. How do I show activity indicator at process time.
private async void ProductTypeButton_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new ProductPage(_ViewModel));
}
CodePudding user response:
Before PushAsync to the ProductPage
, you need make the ActivityIndicator
run and after successfully navigating to ProductPage
, you can set IsLoading = false
. Here's the code snippet below for your reference:
Code-behind:
private bool _isLoading;
public bool IsLoading
{
get => _isLoading;
set
{
_isLoading = value;
OnPropertyChanged("IsLoading");
}
}
public MainPage()
{
InitializeComponent();
BindingContext = this;
}
private async void Button_Clicked(object sender, EventArgs e)
{
IsLoading = true;
//set the delay time to push smoothly
await Task.Delay(300);
try
{
await Navigation.PushAsync(new ProductPage());
}
finally
{
IsLoading = false;
}
}
Xaml:
<ActivityIndicator IsRunning="{Binding IsLoading}" ></ActivityIndicator>