可观察集合添加对象不刷新视图

Observable collection Add object doesn't refresh view

这是我的代码,当我按下与 Clicked 属性 addische 绑定的按钮时,新项目被添加到 ListView 但我在列表中看不到它。

public partial class GS : ContentPage
{
    private GSViewModel _viewModel;

    public GS()
    {
        InitializeComponent();
        BindingContext = _viewModel = new GSViewModel();
    }

    private void addische(object sender, EventArgs e)
    {
        _viewModel.newItemAdded();
    }

    public class GSViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public ObservableCollection<schItem> _scheListItem;
        public ObservableCollection<schItem> Items { get { return _scheListItem; }
            private set
            {
                if (_scheListItem != value)
                {
                    _scheListItem = value;
                    OnPropertyChanged();
                }
            }
        }

        public void newItemAdded()
        {
            Items.Add(new schItem
            {
                realm_id = 133,
                list_id = 33
            });
        }

        public GSViewModel()
        {
            Items = new ObservableCollection<schItem>();
            initListView();
        }

        public void initListView()
        {
           //get data
        }

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public class schItem
    {
        public int realm_id { get; set; }
        public int list_id { get; set; }
        }
    }

也许我在 INotifyPropertyChanged class 中遗漏了什么。

I'm debugging in Android Device

您可能看不到任何内容的几个原因。

  1. 您的绑定有误,因此您将看不到任何文本。修复变化

          <Label Text = "{Binding name}" HeightRequest="20" FontAttributes="Bold"/>
          <Label Text = "{Binding data, StringFormat='a {0:F0}'}" />
    

      <Label Text = "{Binding realm_id}" HeightRequest="20" FontAttributes="Bold"/>
      <Label Text = "{Binding list_id}" />
  1. 检查 "delete.png" 是否存在于正确的位置并且不是 "delete.jpg"

  2. 修复后删除 ListView IsEnabled="False"