Perhaps this question has been asked and solved many times, but I may be using the wrong terms, for I've not come up with an answer thus far.
So I have an ObservableCollection and I've used reflection to call the 'CollectionChanged' event handler.
It looks like this ('o' being the ObservableCollection in question, also obtained by reflection):
EventInfo evi = o.GetType().GetEvent("CollectionChanged", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
var eventHandler = new Action<object, NotifyCollectionChangedEventArgs>(
(s, a) =>
{
// Event code here
});
var del = Delegate.CreateDelegate(evi.EventHandlerType, eventHandler.Method);
evi.AddEventHandler(o, del);
The calling of this action is automated and is called on a change to the elements of the property 'o'. I can call message boxes and such like, but I wish to capture some kind of information inside this action. In particular, the class in which this all sits has an ID which is a simple int. I would like to capture this int and use it within the action. I can't seem to add any additional parameters due to the automated nature of it, so I'm not sure how to manage that.
Aucun commentaire:
Enregistrer un commentaire