Я пытался получить доступ к переменной из моего кода XAML через привязку. Я не знаю почему, но я могу получить доступ к переменной, но я не получаю никакого значения. Код XAML не получает никакого значения. Когда я помещаю переменную за пределами , все работает нормально. Вот пример кода: < /p>
< /code>
Изменить: < /p>
Вот код позади: < /p>
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using neview.Model.Profile;
using System.Collections.ObjectModel;
namespace neview.ViewModel.Profile
{
public partial class ProfileViewModel : ObservableObject
{
public ProfileViewModel(ImagesLoad postLoad)
{
tempColNum = 1;
this.imagesLoad = postLoad;
isRefreshing = false;
}
//------------------------------------------------------------------------
// COMMANDS
// get images
[RelayCommand]
public async Task GetImagesAsync()
{
var localMainPost = await imagesLoad.GetImages();
if (imagesCollection.Count() != 0)
{
imagesCollection.Clear();
}
foreach (var i in localMainPost)
{
imagesCollection.Add(i);
}
IsRefreshing = false;
}
//------------------------------------------------------------------------
// VARIABLES
public ObservableCollection imagesCollection { get; } = new();
ImagesLoad imagesLoad;
[ObservableProperty]
bool isRefreshing;
[ObservableProperty]
int tempColNum;
}
}
Подробнее здесь: https://stackoverflow.com/questions/759 ... plate-maui