Ohad Horesh
Ohad Horesh

Reputation: 4390

WPF How to bind the same event handler to two different controls

I have a UI with a search text box and a button that that should be clicked when the user want to preform the search. (like a search engine UI)
I want that the same event handler will be called when the user hit the search button and when the user hit enter in the text box.

I can easily hack it but my guess is that WPF has it's own 'right' way of doing it.
So what is the WPF way of doing it right?

Thanks.

Upvotes: 0

Views: 758

Answers (1)

Ilya Khaprov
Ilya Khaprov

Reputation: 2524

There are different delegates for click and keypressed events. So extract your code in method named like 'DoSearch', then connect different (mb anonymous) handlers to events and call DoSearch inside handlers

Upvotes: 3

Related Questions