Skip to content

Commit

Permalink
Merge pull request #498 from VacuumBreather/fix/ishittestvisible_ignored
Browse files Browse the repository at this point in the history
Check for IsHitTestVisible during hit tests
  • Loading branch information
punker76 authored Dec 5, 2024
2 parents a72612b + 651405e commit 42f09cc
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/GongSolutions.WPF.DragDrop/Utilities/HitTestUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,34 @@ private static T GetHitTestElement4Type<T>(object sender, Point elementPosition)
return null;
}

var hit = VisualTreeHelper.HitTest(visual, elementPosition);
HitTestResult hit = null;

VisualTreeHelper.HitTest(
visual,
potentialHitTestTarget =>
{
var isHitTestVisible = false;

if (potentialHitTestTarget is UIElement uiElement)
{
isHitTestVisible = uiElement.IsHitTestVisible;
}
else if (potentialHitTestTarget is UIElement3D uiElement3D)
{
isHitTestVisible = uiElement3D.IsHitTestVisible;
}

return isHitTestVisible ? HitTestFilterBehavior.Continue : HitTestFilterBehavior.ContinueSkipSelf;
},
result =>
{
hit = result;

// Stop on first element found
return HitTestResultBehavior.Stop;
},
new PointHitTestParameters(elementPosition)
);

return hit?.VisualHit.GetVisualAncestor<T>();
}
Expand Down

0 comments on commit 42f09cc

Please sign in to comment.