And*_*ndy 42
您还可以尝试使用Mouse.DirectlyOver属性来获取鼠标下最顶层的元素.
Dav*_*itt 39
从" WPF Unleashed ",第383页:
视觉命中测试可以告知您与位置相交的所有内容
Visual,[...]您必须使用[VisualTreeHelper.]HitTest接受HitTestResultCallback委托的 方法 .在此版本的HitTest返回之前,将为每个相关调用一次委托Visual,从最顶层开始到最底层结束.
这种回调的签名是
HitTestResultBehavior Callback(HitTestResult result)
Run Code Online (Sandbox Code Playgroud)
并且它必须返回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;
}
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请参阅MSDN文档VisualTreeHelper.HitTest.
| 归档时间: |
|
| 查看次数: |
38846 次 |
| 最近记录: |