0

When I am attaching simple event handler, I can do:

expandable_list_item_inspection_interface_btnCamera.Click -= Expandable_list_item_inspection_interface_btnCamera_Click;

I want to remove an already attached event handler to insure the click event doesn't get called multiple times when attaching a event programmatically in the Adapter of the ExpandableListView .. but if I attach an event like this:

expandable_list_item_inspection_interface_btnCamera.Click -= (sender, e) => btnCamera_Click(sender, e, expandable_list_item_inspection_interface_btnImage1);
expandable_list_item_inspection_interface_btnCamera.Click += (sender, e) => btnCamera_Click(sender, e, expandable_list_item_inspection_interface_btnImage1);

the event still gets called multiple times, although I first removed the event handler and then added another. How do I prevent this?

Palle Due
  • 5,929
  • 4
  • 17
  • 32
Bibek Gautam
  • 581
  • 8
  • 30

1 Answers1

0

You need to remember the delegate instance you used like this.

var handler = (sender, e) => btnCamera_Click(sender, e, expandable_list_item_inspection_interface_btnImage1);

then use it attach and remove like this

expandable_list_item_inspection_interface_btnCamera.Click -= handler 
expandable_list_item_inspection_interface_btnCamera.Click += handler 
Manish Parakhiya
  • 3,732
  • 3
  • 22
  • 25