wpf - WPF中的 "Capture the mouse"是什么意思?

标签 wpf events mouse

System.Windows.UIElement 上有一个CaptureMouse() 和一个配对的ReleaseMouseCapture() 方法。在此WPF DragDrop示例中,他们在 MouseDown 上调用 CaptureMouse,并在 MouseUp 上释放它。 documentation in MSDN几乎毫无用处 - “CaptureMouse -> 捕获鼠标。”

在尝试之前,我的脑海中假设它以某种方式将鼠标锁定在 UIElement 范围内,但当我尝试它时,情况显然并非如此。通过实验,这似乎与鼠标位于 UIElement 之外时响应事件有关,但又不想成为 cargo cult programmer我不想仅仅使用它,因为示例使用了它,我想要一个关于它含义的权威描述。

最佳答案

来自Capture and Uncapture the Mouse在 MSDN 上:

When an object captures the mouse, all mouse related events are treated as if the object with mouse capture perform the event, even if the mouse pointer is over another object.

只有捕获控件会接收鼠标事件,直到释放为止。

捕获鼠标对于拖动非常有用,因为所有拖动代码都可以存在于一个控件中,而不是分布在多个控件中。

关于wpf - WPF中的 "Capture the mouse"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/942357/

相关文章:

.net - 在 WPF 应用程序上与艺术家合作的最佳方式是什么?

.net - WPF 应用程序布局

javascript - 尝试通过传入函数来绑定(bind)回调会引发错误

javascript - 如何禁用 Opera 鼠标手势?

c# - 如何在 C# 中使用内联 XAML 在代码隐藏中轻松创建自定义对象

wpf - 如何在 WPF UI 代码中等待后台线程/操作完成?

Android:通过 MTP 连接时如何检测 MediaStore 的变化

c# - 捕获和处理 Web 浏览器关闭事件

c++ - Win32 中缺少鼠标移动消息

apache-flex - DataGrid itemEditor 中的下拉列表中的滚动条不起作用