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
CarPropertyChangedis calledStateHasChangedis called- The property of the
viewModelis 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()); }}