Мой XAML:
Код: Выделить всё
Код: Выделить всё
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using FireLearn.Models;
namespace FireLearn.ViewModels
{
class CategoryViewModel : ObservableObject
{
public ObservableCollection categories = new ObservableCollection();
public ObservableCollection Categories
{
get => categories;
set => SetProperty(ref categories, value);
}
public bool ListRefreshing = false;
public ICommand RefreshCommand;
public CategoryViewModel()
{
loadFromSource();
RefreshCommand = new Command(async () =>
{
if (!ListRefreshing)
{
ListRefreshing = true;
try
{
await loadFromSource();
}
finally
{
ListRefreshing = false;
}
}
});
}
public async Task loadFromSource()
{
HttpClient httpClient = new()
{
Timeout = new TimeSpan(0,0,10)
};
Uri uri = new Uri("https://somewodpresssite/wp-json/wp/v2/categories");
HttpResponseMessage msg = await httpClient.GetAsync(uri);
if (msg.IsSuccessStatusCode)
{
var result = CategoryModel.FromJson(await msg.Content.ReadAsStringAsync());
Categories = new ObservableCollection(result);
}
Debug.WriteLine("List Refreshed");
}
}
}
[0:] Microsoft.Maui.Controls.Xaml.Diagnostics.BindingDiagnostics:
Предупреждение: свойство ListRefreshing не найдено в
'FireLearn.ViewModels.CategoryViewModel', целевое свойство:
'Microsoft.Maui.Controls.ListView.IsRefreshing'
Я попробовал на Android и iOS с тем же результатом и не понимаю, что я здесь пропустил.
Подробнее здесь: https://stackoverflow.com/questions/749 ... ot-working
Мобильная версия