I have a list of simple properties, and I am trying to reflect the change of one of the properties in the list in the UI.
I removed this question as I got this to work in a Blazor fiddle, but Im still not able to do it in my regular code. My code I am using, I have an AppStateService that has a list of items and a Complete() method that will look at the Items and set the one I specify to be complete.
In another Service, call it MyService, I inject the AppStateService, and in a method in MyService I make a call to Complete() from the AppStateService. It does show it changing the Item's IsComplete property, but it isnt reflected in the UI. Ive tried using a StateHasChanged(), EventCallBack, Action event etc.
Here is a watered down version.
public class Foo { public string Title {get;set;} = ""; public bool IsComplete {get;set;}}List<Foo> list = new() { new() { Title = "Title 1"}, new() { Title = "Title 2"}};EventCallback OnComplete { get; set; }void Complete(){ list[0].IsComplete = true; StateHasChanged(); //trying this OnComplete.InvokeAsync(); //and this.}In the UI
@foreach(Foo item in list){<div>@item.IsComplete - @item.Title</div>}<button type="button" @onClick="Complete">Complete Me</button>Ive tried EventCallBacks and just calling StateHasChanged(), but neither one reflects the change in the list.
Any help is appreciated. Im missing something I feel is a simple thing. Of course it works in my fiddle, so there is something else that my app is doing that this isn't.