Skip to content

VisualTreeHelper.FindElementsInHostCoordinates ignores clips (Clip, layout clip, ScrollViewer viewport) #25269

Open

Description

@MartinZikmund

Current behavior

VisualTreeHelper.FindElementsInHostCoordinates(Point, UIElement) returns elements at points where they are clipped away. IsElementIntersecting only tests the element's transformed layout slot, so UIElement.Clip on an ancestor, the layout clip and a ScrollViewer viewport are all ignored. Pointer hit-testing (SearchDownForTopMostElementAt) does respect clips, so the two disagree: a point that can't be clicked still "hits" the element.

Expected behavior

The element must not be returned at points outside its effective clip, same as WinUI. WinUI's CUIElement::BoundsTestInternalImpl clips the test against the element clip (GetHandOffVisualClipOrElementClip) and the layout clip (LayoutClipGeometry->ClipToFill) before testing the element's bounds (uielement.cpp, BoundsTestInternalImpl). Confirmed by reading the WinUI C++ source; I did not run a native WinUI repro.

How to reproduce it

  1. Add this runtime test to src/Uno.UI.RuntimeTests/Microsoft/UI/Xaml/Media/Given_VisualTreeHelper.cs (public API only, so it also compiles on WinUI):
[TestMethod]
public async Task When_FindElementsInHostCoordinates_Clipped()
{
    Border visible = new() { Width = 20, Height = 20, Background = new SolidColorBrush(Colors.Green) };
    Border clipped = new() { Width = 20, Height = 20, Background = new SolidColorBrush(Colors.Red) };
    Canvas.SetLeft(visible, 10);
    Canvas.SetTop(visible, 10);
    Canvas.SetLeft(clipped, 70);
    Canvas.SetTop(clipped, 70);

    Canvas sut = new()
    {
        Width = 100,
        Height = 100,
        Clip = new RectangleGeometry { Rect = new Rect(0, 0, 50, 50) },
        Children = { visible, clipped },
    };
    await UITestHelper.Load(sut);

    var visibleHits = VisualTreeHelper.FindElementsInHostCoordinates(visible.GetAbsoluteBounds().GetCenter(), sut).ToArray();
    var clippedHits = VisualTreeHelper.FindElementsInHostCoordinates(clipped.GetAbsoluteBounds().GetCenter(), sut).ToArray();

    Assert.IsTrue(visibleHits.Contains(visible), "Control: the child inside the clip should be found");
    Assert.IsFalse(clippedHits.Contains(clipped), "A child outside the parent's Clip should not be found");
}
  1. Run it on Skia Desktop (see the /runtime-tests instructions in the repo).
  2. The control assertion passes; the last assertion fails (clippedHits.Contains(clipped) is true), although clipped is entirely outside the 50x50 clip.

A ScrollViewer viewport or layout clip goes through the same code, so a child scrolled out of view should be returned too. Only the Clip case is runtime-verified.

Workaround

None through public API. Internally VisualTreeHelper.HitTest is clip-aware.

Works on UWP/WinUI

Yes (per the WinUI source above).

Environment

Skia (reproduced on Skia Desktop)

NuGet package version(s)

Uno master @ 951b7b4, net11.0-desktop

Affected platforms

Skia (Desktop; the code is shared with all heads)

IDE

Not applicable

Relevant plugins

None

Anything else we need to know?

Root cause: IsElementIntersecting takes LayoutInformation.GetLayoutSlot transformed to the root and does Contains(point). Nothing intersects it with the element, layout or transition clips. The recursion in FindElementsInHostCoordinates also doesn't check whether the subtree root itself is hit-test visible or visible.

Related, different problems with the same API: #25267 (duplicates and ordering), #24309 (ancestors only on Skia).

Activity

  1. added
    kind/bug
    triage/untriaged
    project/pointers 🖱️
    platform/all
    difficulty/medium 🤔
    on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty/medium 🤔kind/bugplatform/allproject/pointers 🖱️triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions