Closed MattePozzy closed 1 year ago
You need to use SetState.
protected override async void OnMounted()
{
var items = await LoadItems();
SetState(state => state.Items = items);
base.OnMounted();
}
You need to use SetState.
protected override async void OnMounted() { var items = await LoadItems(); SetState(state => state.Items = items); base.OnMounted(); }
Thank you for the reply! I do SetState in OnAppearing of the ContentPage. I also have tried to do it in OnMounted but doesn't work (sorry but the code I have posted is outdated, I fix it now).
You need to keep the async/await at the OnMounted level.
works:
protected override async void OnMounted()
{
var items = await LoadItems();
SetState(state => state.Items = items);
base.OnMounted();
}
vs. (doesn't work):
protected override void OnMounted()
{
SetState(async s => s.Items = await LoadItems());
base.OnMounted();
}
At least works on iOS for me. If you don't want to async await in OnMounted, you will have to use Task.Run and put SetState inside it.
You need to keep the async/await at the OnMounted level.
works:
protected override async void OnMounted() { var items = await LoadItems(); SetState(state => state.Items = items); base.OnMounted(); }
vs. (doesn't work):
protected override void OnMounted() { SetState(async s => s.Items = await LoadItems()); base.OnMounted(); }
At least works on iOS for me. If you don't want to async await in OnMounted, you will have to use Task.Run and put SetState inside it.
Thank you, in this way works! I have load the items in the OnAppearing method of the ContentPage, and works also there.
Thank you!
Hi, I need to load the items of a listview usign an async method that load the data from a sqlite.
I have tried to load them in OnMounted method and OnAppearing of ContentPage but the items are not rendered.
This is the code used:
attached a sample.
MauiTest.zip
Thank you.