I have created a TextBox
dynamically and attached a Tap event handler to it using:
control.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(OnClick1);
It works fine. But, now I want to change the event handler to point to some different method. I tried:
control.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(OnClick2);
But, it still points to first event handler. i.e. OnClick1
. What can I do to make it point OnClick2
? Also is there a way to remove this event handler completely?
You need to remove the first handler first:
control.Tap -= OnClick1;
control.Tap += OnClick2;
(Note the rather simpler use of method group conversions, instead of explicitly creating the event handler. It does the same thing, but is much more readable.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With