Charles Zhang
Charles Zhang

Reputation: 91

How to use AddHandler to add event handler for a click event on a button in WPF

Hey collective brain,

So I need to add some additional click behavior to an existing button of a control whose click event, i assume, is handled somewhere in its encapsulated code. So I am using AddHandler() on the button, which is a CalendarDayButton, I can't seem to find a handler for click event. For the first argument of the AddHandler, I used ButtonBase.ClickEvent, and for the second I just used new EventHandler(button_click), and the third is "true". And then I get the "Handler type is mismatched." exception. Any input on this would be highly appreciated.

Upvotes: 1

Views: 2403

Answers (1)

Reed Copsey
Reed Copsey

Reputation: 564851

The problem is that, in WPF, ButtonBase.Click is a RoutedEventHandler. You need to add an appropriate delegate (not EventHandler, but one that implements RoutedEventHandler).

Upvotes: 5

Related Questions