Search code examples
c#multithreadingasync-awaitmauibusyindicator

Display BusyIndicator during a GoToAsync Call


I have a .NET Maui app that loads a list of people from a database. Tapping that person in the ListView then displays an information page about that person.

Although this works well, there is quite a delay while the additional information is pulled from the database after calling GoToAsync:

Shell.Current.GoToAsync($"//people/person", new Dictionary<string, object> { { "Person", e.Target } });

I have the SyncFusion MAUI suite, and am using the BusyIndicator:

<sfCore:SfBusyIndicator VerticalOptions="Center" HorizontalOptions="Center"
                            IsRunning="{Binding Loading}" AnimationType="Cupertino" Title="Loading..." />

If I set my "Loading" property to true, the indicator does display correctly.

I've tried wrapping the GoToAsync call:

            Loading = true;

            await Shell.Current.GoToAsync($"//people/person", new Dictionary<string, object> { { "Person", person } });

            Loading = false;

I've also tried not wrapping the GoToAsync call in a Task.Run(), have tried calling GoToAsync without awaiting and have tried using the Application Dispatcher to call GoToAsync, but whatever I do, the busy indicator is not shown.

I removed the "Loading = false" call, and when I navigate back to the original search page, my BusyIndicator is doing what it should, so it appears that BusyIndicator is activated after GoToAsync has completed.

What's the correct way to deal with this?


Solution

  • Like nvoigt said. You can add BusyIndicator to the Page (an information page about person).

    You can set "Loading = true;" in OnAppearing and set "Loading = false" after loading the personal information code