Source Files
My repo is at https://github.com/bjscharf/BlazorPopUpOnLoadPoC/tree/master which has code taken from https://github.com/dahln/BlazorSpinner/blob/master/BlazorSpinner/Spinner.razor
Intention
Using .NET 9.0.x, C#, Blazor, and the default project, I am trying to show a spinner while the weather data loads on the weather page.
Problem
The spinner will not close or the UI is not updated to show this.
Working Parts
The weather page has:
protected override async Task OnParametersSetAsync(){ _spinnerService.Show();//this works // Simulate asynchronous loading to demonstrate streaming rendering await Task.Delay(3000); var startDate = DateOnly.FromDateTime(DateTime.Now); var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" }; forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = startDate.AddDays(index), TemperatureC = Random.Shared.Next(-20, 55), Summary = summaries[Random.Shared.Next(summaries.Length)] }).ToArray(); _spinnerService.Hide();//This does not work}Both the show and hide are set in Spinner.razor:
protected override void OnInitialized(){ _spinnerService.OnShow += ShowLoadingSpinner; _spinnerService.OnHide += HideLoadingSpinner;}And the SpinnerService is injected into the weather page. The service allows these to be invoked and it is added as a scoped service in program.cs.
When I step through it, the HideLoadingSpinner() method is executed. But the UI is not updated. I have tried to hide it using the IsVisible flag and also by adding/removing a "hidden" class. No UI updates seem to happen on the Hide() method, but they do for the Show() method.
Any thoughts as to what I am doing wrong or how to fix it would be appreciated. I apologize if this is not formatted correctly--I will be glad to fix if needed. Thanks for your consideration.