2

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.

3
  • You should probably take a look here.
    – DHN
    Commented Mar 18, 2013 at 15:54
  • This is a perfectly valid question. How do mouse events work in WPF. Looks like the people who voted to close just didn't know the topic well enough. Commented Mar 18, 2013 at 22:19
  • Anyway, if this does get re-opened. Someone respond to this comment so we can talk about Attached Events and LIFE in WPF. Commented Mar 18, 2013 at 22:40

1 Answer 1

5

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.

1
  • Thanks the links you provided are very useful.
    – yo chauhan
    Commented Mar 18, 2013 at 16:11

Not the answer you're looking for? Browse other questions tagged or ask your own question.