My Blazor component is not being re-rendered after receiving a new value for its hashset parameter from a service I have implemented. The parameter is set by an event in the service.
This is the main page where my component in question "GenericGridComponent" is located. When rendering the page, a database query is called by await Task.Run(() => DataExchange.AccessData<fcPersons>());, which stores a hashset from a database in the DataExchange service.
@inject DataExchange DataExchange@rendermode InteractiveServer<GenericGridComponent T="fcPersonen"></GenericGridComponent>@code { protected async override OnAfterRender(Boolean firstRender) { if (firstRender == true) { await Task.Run(() => DataExchange.AccessData<fcPersonen>()); } }}In the GenericGridComponent, an event is bound in OnAfterRender, which assigns a new value to the hashset parameter Elements by the service. The value is successfully assigned to the parameter, but this does not re-render the user interface of my component. In this case, I would like to dispense with the StateHasChanged() method, because as far as I know, Blazor should automatically register a change to a parameter and re-render the specific content.
@typeparam T where T :class, new()@inject DataExchange DataExchange@using System.Reflection@if (Elements != null){<table class="table table-bordered"><thead class="thead"><tr> @foreach (PropertyInfo propertyInfo in Elements.First().GetType().GetProperties()) {<th scope="col"><div style="width:fit-content;"><p>@propertyInfo.Name</p></div></th> }</tr></thead><tbody><Virtualize TItem="T" Context="obj" Items="Elements"><tr> @foreach (PropertyInfo propertyInfo in obj.GetType().GetProperties()) {<td>@propertyInfo.GetValue(obj)</td> }</tr></Virtualize></tbody></table>}@code { protected override void OnAfterRender(Boolean firstRender) { if (firstRender == true) { DataExchange.DataChanged += DataChanged; } } private void DataChanged() { Elements = DataExchange.GetData<T>(); } private HashSet<T>? Elements { get; set; }}It was expected that the component would redraw itself due to the change in the bound property.