WPF Get Element(s) under mouse
有没有一种WPF的方式来获取MouseMove事件下的鼠标下的元素数组?
From "WPF Unleashed", page 383:
Visual hit testing can inform you about all Visual
s that intersect a location, [...] you must use [...] the [VisualTreeHelper.]HitTest
method that accepts a HitTestResultCallback
delegate. Before this version of HitTest
returns, the delegate is invoked once for each relevant Visual
, starting from the topmost and ending at the bottommost.
The signature of such a callback is
HitTestResultBehavior Callback(HitTestResult result)
and it has to return HitTestResultBehaviour.Continue
to receive further hits, as shown below (from the linked page on MSDN):
// Return the result of the hit test to the callback.
public HitTestResultBehavior MyHitTestResult(HitTestResult result)
{
// Add the hit test result to the list that will be processed after the enumeration.
hitResultsList.Add(result.VisualHit);
// Set the behavior to return visuals at all z-order levels.
return HitTestResultBehavior.Continue;
}
For further information, please consult the MSDN documentation for VisualTreeHelper.HitTest
.
您还可以尝试使用Mouse.DirectlyOver属性来获取鼠标下最顶端的元素。
Can you use the VisualTreeHelper.HitTest ?
http://lukieb.blogspot.com/2008/07/visualtreehelperhittest.html
链接地址: http://www.djcxy.com/p/39538.html上一篇: 延迟jquery悬停事件?
下一篇: WPF获取鼠标下的元素