有没有办法对禁用的控件进行命中测试?
我试图检测鼠标光标下的控件,无论该控件是否启用。
VisualTreeHelper.FindElementsInHostCooperatives
会忽略 IsEnabled
属性设置为 false
的控件。有什么方法可以改变这种行为,或者有任何其他方法可以在特定的屏幕位置找到控件?
谢谢。
I'm trying to detect the control under the mouse cursor, regardless of whether the control is enabled or not.
VisualTreeHelper.FindElementsInHostCoordinates
ignores controls that have their IsEnabled
property set to false
. Is there any way to change this behavior, or any other way to find the controls at a specific screen location?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以实现自己的递归方法来搜索子树并将每个元素转换为应用程序的根视觉对象,以获得其“绝对”边界,然后测试“绝对”鼠标点是否在该区域内。
这可能不完全是您所需要的,但应该可以帮助您入门。我基本上使用相同的签名进行了替换
FindElementsInHostCooperatives
,因此可以在 MouseMove 处理程序中以相同的方式使用它。此方法仅尝试“命中测试”FrameworkElements,因为它需要知道 ActualWidth 和 ActualHeight 来计算命中区域。然后,您只需确保从 MouseMove 处理程序传入的点是相对于
Application.Current.RootVisual
的:You could implement your own recursive method to search the subtree and transform each element to the application's root visual in order to get its "absolute" bounds and then test to see if the "absolute" mouse point is within that region.
This might not be exactly what you need but should get you started. I basically made a replacement
FindElementsInHostCoordinates
with the same signature so it can be used in the same manner in your MouseMove handler. This method only tries to "hit test" FrameworkElements since it needs to know the ActualWidth and ActualHeight to calculate the hit region.You would then just need to make sure the point you are passing in from the MouseMove handler is relative to
Application.Current.RootVisual
: