INotifyPropertyChanged event not firing when Observable Collection changed in WPF in VB.NET

可紊 提交于 2019-12-06 15:51:53

No PropertyChanged event will be raised automatically simply because the type of a property is ObservableCollection. You would have to raise it in the setter:

Set(ByVal value As ObservableCollection(Of Person)) 
    _coreInfoData = value
    OnPropertyChanged("CoreInfoData")
End Set 

It looks like you're assigning a value to your ObservableCollection which doesn't change your collection it replaces it. Either raise a PropertyChanged event for for the CoreInfoData property or add the items one by one from the set value to the ObservableCollection (the ObservableCollection should manage the raising of the PropertyChanged event for you).

You are confusing INotifyPropertyChanged with INotifyCollectionChanged.

ObservableCollection does implement INotifyPropertyChanged, this is used to fire the event for properties like Count and the indexer Item[]. It does not extend to the functionality you require it to achieve.

first - why is your collection Shared/static?

when working with ObservableColelction then usually you create a instance just once and use clear, add remove.

if you wanna set a new instance like you did in your setter you have to call OnPropertyChanged("CoreInfoData") too.

but i would prefer clear and add

    CoreInfoData.Clear()
    CoreInfoData.AddRange(GetRecords())
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!