且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

添加项目时,ObservableCollection不更新列表

更新时间:2023-11-28 17:47:34

将代码更改为此:

public class AllTracksViewModel : INotifyPropertyChanged
{
    ObservableCollection<Track> trackListObservable;

    public event PropertyChangedEventHandler PropertyChanged;

    public ObservableCollection<Track> TrackListObservable {
      get { return trackListObservable; }
      set {
        trackListObservable = value;
        if(PropertyChanged!=null) {
          PropertyChanged(this, new PropertyChangedEventArgs("TrackListObservable"));
        }
      }
}

    public AllTracksViewModel()
    {
        TrackListObservable = new ObservableCollection<Track>();
    }
}

仅说明原因:ViewModel的每个属性都应通知其更改.

Just to explain why: every property of your ViewModel should notify of its changes.