Код: Выделить всё
ViewModel:
Код: Выделить всё
[ObservableProperty]
public ObservableCollection news = new();
public async Task LoadNoticiasAsync()
{
if (isBusy)
return;
try
{
isBusy = true;
if (news == null)
{
_allNews = (await _newsService.GetNoticiasAsync()).OrderByDescending(a => a.Date).ToList();
}
UpdateNewsView(_allNews);
}
catch (Exception ex)
{
Debug.WriteLine($"Error al cargar noticias: {ex.Message}");
}
finally { isBusy = false; }
}
public void UpdateNewsView(List news)
{
if (News.Count != 0)
News.Clear();
foreach(var singleNew in news)
{
News.Add(singleNew);
}
}
Я думал, что очистка observableCollection и добавление элементов сработает, но я ошибался. Некоторая помощь была бы полезна.
Подробнее здесь: https://stackoverflow.com/questions/793 ... ew-in-maui
Мобильная версия