gpt4 book ai didi

WPF在鼠标下获取元素

转载 作者:行者123 更新时间:2023-12-03 08:13:24 27 4
gpt4 key购买 nike

WPF 有没有办法在 MouseMove 事件上获取鼠标下的元素数组?

最佳答案

来自“WPF Unleashed”,第 383 页:

Visual hit testing can inform youabout all Visuals that intersect alocation, [...] you must use [...] the[VisualTreeHelper.]HitTest method that accepts aHitTestResultCallback delegate. Beforethis version of HitTest returns, thedelegate is invoked once for eachrelevant Visual, starting from thetopmost and ending at the bottommost.


这种回调的签名是
HitTestResultBehavior Callback(HitTestResult result)
它必须返回 HitTestResultBehaviour.Continue接收更多点击,如下所示(来自 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;
}
如需更多信息,请咨询 MSDN documentation for VisualTreeHelper.HitTest .

关于WPF在鼠标下获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45813/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com