How do mouse events work in WPF?

坚强是说给别人听的谎言 提交于 2019-12-10 10:44:56

问题


How do WPF controls know that Mouse Event Happend on it so that it can Raise its Mouse Event.

For example How does a Button control know capture the MouseDown and MouseUp event and translate it into a click event.


回答1:


Windows uses a Messaging model to notify GUI elements of what is happening. Windows puts these messages into a message queue, and each window is constantly checking this queue to see what messages are present. This is frequently called a message loop. The window is then responsible for taking the messages destined for itself, and performing the necessary action (such as raising an event for user code to respond to). I would suggest reading this and this to learn more about the Message Loop and Messages.

In WinForms, each control was its own window, so each control had its own message queue. This is not the case for WPF. WPF handles this differently as WPF treats the entire window as a single item, composing the necessary elements at runtime. I'd recommend reading this to learn more about how WPF handles this situation.

There are many other resources out there, besides the ones I've listed here, if you just search for Windows Messages, Windows Message Loop and throw WPF into the mix.



来源:https://stackoverflow.com/questions/15481106/how-do-mouse-events-work-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!