yo chauhan
yo chauhan

Reputation: 12295

How do mouse events work in WPF?

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.

Upvotes: 2

Views: 869

Answers (1)

Brian S
Brian S

Reputation: 5785

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.

Upvotes: 5

Related Questions