Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Component is not rendering after StateHasChanged call

$
0
0

Coming from a WPF background where you normally just bind to a property which updates the view, I want to update the information in a component when I have new data.

So I have a item view that is bound to the ViewModel and updates when the model updates.

Then I thought it should call a statehaschanged so that through the viewmodel the model data can be accessed. But it never updates.

I've checked and verified that:

  • The Event is thrown
  • CarPropertyChanged is called
  • StateHasChanged is called
  • The property of the viewModel is called and returns the new value

However the UI doesn't update

Does anyone know what the reason could be?

@foreach (var car in CarVMs){<CarStandingItem CarVM="car"></CarStandingItem>}@code{   [Parameter] public List<CarViewModel> CarVMs { get; set; }    Session currentlyDisplayedSession;    protected override void OnInitialized()    {        CarVMs = new List<CarViewModel>();        currentlyDisplayedSession = SessionManager.GetInstance().GetCurrentSession();        foreach (var car in currentlyDisplayedSession.Cars)        {            CarVMs.Add(new CarViewModel(car));        }        currentlyDisplayedSession = SessionManager.GetInstance().GetCurrentSession();    }}
<MudGrid><MudItem><MudText>@CarVM.TimeStamp</MudText></MudItem></MudGrid>@code {    [Parameter] public CarViewModel CarVM { get; set; }    protected override void OnInitialized()    {        CarVM.GetCar().PropertyChanged += CarOnPropertyChanged;    }    private async void CarOnPropertyChanged(object? sender, PropertyChangedEventArgs e)    {        await InvokeAsync(() => StateHasChanged());    }}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>