You can implement your own recursive method to search for a subtree and convert each element into a visual root file of the application to get its “absolute” borders, and then check if the “absolute” mouse point is in this region.
, , . FindElementsInHostCoordinates , MouseMove. " " FrameworkElements, ActualWidth ActualHeight .
private IEnumerable<UIElement> FindAllElementsInHostCoordinates(Point intersectingPoint, UIElement subTree)
{
var results = new List<UIElement>();
int count = VisualTreeHelper.GetChildrenCount(subTree);
for (int i = 0; i < count; i++)
{
var child = VisualTreeHelper.GetChild(subTree, i) as FrameworkElement;
if (child != null)
{
GeneralTransform gt = child.TransformToVisual(Application.Current.RootVisual as UIElement);
Point offset = gt.Transform(new Point(0, 0));
Rect elementBounds = new Rect(offset.X, offset.Y, child.ActualWidth, child.ActualHeight);
if (IsInBounds(intersectingPoint, elementBounds))
{
results.Add(child as UIElement);
}
}
results.AddRange(FindAllElementsInHostCoordinates(intersectingPoint, child));
}
return results;
}
private bool IsInBounds(Point point, Rect bounds)
{
if (point.X > bounds.Left && point.X < bounds.Right &&
point.Y < bounds.Bottom && point.Y > bounds.Top)
{
return true;
}
return false;
}
, , MouseMove, Application.Current.RootVisual:
IEnumerable<UIElement> elements = FindAllElementsInHostCoordinates(e.GetPosition(Application.Current.RootVisual), this);