我需要将集合更改的事件添加到集合对象中:
Dim Coleccion As Object = New ObservableCollection(Of Entidad)
AddHandler Coleccion.CollectionChanged, AddressOf Coleccion_Cambiada但是它抛出: CollectionChanged不是对象的事件
所以,我试过:
Dim Evento As EventInfo = Coleccion.GetType().GetEvent("CollectionChanged")
Evento.AddEventHandler(Coleccion, New EventHandler(AddressOf Coleccion_Cambiada))但是它抛出:无法将System.Collections.Specialized.NotifyCollectionChangedEventHandler转换为System.EventHandler
那么,我怎样才能为一个我不知道的一般观察结果添加一个事件呢?
谢谢。
发布于 2017-04-10 18:20:01
当您尝试使用反射添加事件处理程序时所遇到的错误是因为CollectionChanged事件没有使用默认的均衡器。您可以通过使用CollectionChanged事件使用的特定的均衡器来修复错误。
Evento.AddEventHandler(Coleccion, New System.Collections.Specialized.NotifyCollectionChangedEventHandler(AddressOf Coleccion_Cambiada))https://stackoverflow.com/questions/43329990
复制相似问题