0

I would like to know, how can I remove all the event handler registered in a particular event in a UWP Control (e.g., button or toggle switch). Consider the fact that I don't have any access to the event handle, so I can't use the deregister method like "some_event -= my_event_handler".

I found some solution [https://stackoverflow.com/questions/91778/how-to-remove-all-event-handlers-from-an-event] in stack overflow for the similar problem using reflection; however the solutions didn't work when I tried to implement the for UWP controls.

Redwan Dipto
  • 41
  • 1
  • 1
  • 6

1 Answers1

0

In UWP document Removing event handlers in code.

It's not usually necessary to remove event handlers in code, even if you added them in code. The object lifetime behavior for most Windows Runtime objects such as pages and controls will destroy the objects when they are disconnected from the main Window and its visual tree, and any delegate references are destroyed too.

If you need to remove the event handler, you can only use -= and UIElement.RemoveHandler, both methods require an event handler.

Junjie Zhu - MSFT
  • 2,086
  • 1
  • 2
  • 6