如何鼠标事件在WPF中工作? [英] How do mouse events work in WPF?

查看:98
本文介绍了如何鼠标事件在WPF中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何WPF控件知道,鼠标事件Happend就可以了,这样就可以提高它的鼠标事件。

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

例如如何Button控件知道捕获的MouseDown和MouseUp事件并将其转换成一个click事件。

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

推荐答案

Windows使用一个消息模型来通知发生了什么GUI元素。窗户把这些消息到消息队列,每个窗口不断地检查队列,看看有什么消息出现。这通常被称为一个消息循环。该窗口是然后负责采取往自身的信息,并执行必要的操作(如引发事件为用户代码来响应)。我建议阅读并的this 以了解更多的消息循环和消息。

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.

在的WinForms ,每个控制了自己的窗口,因此,每个控制都有自己的消息队列。这不是为WPF的情况。 WPF处理这种不同为WPF将整个窗口作为一个单一的项目,组成在运行时的必要因素。我建议你阅读这个详细了解WPF如何处理这种情况。

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.

有许多其他资源在那里,除了我在这里列出,如果你只是搜索Windows消息的那些,Windows消息循环,并抛出WPF混进去。

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.

这篇关于如何鼠标事件在WPF中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆