Change an already set event handler runtime

I created a dynamic one TextBoxand connected a Tap event handler to it using:

control.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(OnClick1);

It works great. But now I want to change the event handler to point to some other method. I tried:

control.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(OnClick2);

But it still points to the handler of the first event. those. OnClick1. What can I do to indicate OnClick2? Also is there a way to completely remove this event handler?

+5
source share
1 answer

First you need to remove the first handler:

control.Tap -= OnClick1;
control.Tap += OnClick2;

( . , .)

+12

All Articles