[英]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. 我有一个带有搜索文本框和一个按钮的UI,当用户要执行搜索时应单击该按钮。 (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. 我希望当用户单击搜索按钮和在文本框中单击Enter时将调用相同的事件处理程序。
I can easily hack it but my guess is that WPF has it's own 'right' way of doing it. 我可以很容易地破解它,但是我猜想WPF拥有自己的“正确”方式。
So what is the WPF way of doing it right? 那么WPF正确的做法是什么?
Thanks. 谢谢。
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
因此,请使用名为“ DoSearch”的方法提取代码,然后将不同的(mb匿名)处理程序连接到事件,并在处理程序中调用DoSearch
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.