문제

MouseMove 이벤트에서 마우스 아래에 요소 배열을 가져오는 WPF 방법이 있습니까?

도움이 되었습니까?

해결책

에서 "WPF 출시", 383페이지:

시각적 히트 테스트에서 알 수 있습니다 모두 Visual위치를 교차하는 s, [...] 당신은 [... [VisualTreeHelper.]HitTest 을 받아들이는 메소드 HitTestResultCallback 대리자.이 버전 이전 HitTest 반품, 대의원은 각 관련마다 한 번 호출됩니다. Visual, 최상위부터 시작하여 병적으로 끝납니다.

이러한 콜백의 서명은 다음과 같습니다.

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 설명서 VisualTreeHelper.HitTest.

다른 팁

Mouse.DirectlyOver 속성을 사용하여 마우스 아래에 있는 최상위 요소를 가져올 수도 있습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top