Skip to content

[Skia] VisualTreeHelper.FindElementsInHostCoordinates returns only ancestors, never the element at the point #24309

Open

Description

@MartinZikmund

What happened

VisualTreeHelper.FindElementsInHostCoordinates does not return the element that is actually at the given point. Called at the exact centre of a Button, it returns only ancestors — the Frame and two ContentPresenters — and never the Button itself.

The button at that point is fully interactive: it is enabled, visible, hit-test visible, correctly positioned, and raises PointerEntered, Click and Tapped when clicked at the same coordinates that the API reports nothing for.

Expected

The returned enumeration should contain the Button (and its template parts), innermost-first, as on WinUI.

Actual

Eight at (174.67,356) size 168.67x59.33 centre (259,385.67) enabled=True
  hit[0] = Frame
  hit[1] = ContentPresenter
  hit[2] = ContentPresenter

The Button is absent. Meanwhile, clicking that same centre point produces:

[EVT] PointerEntered
[EVT] Click
[EVT] Tapped

So real hit-testing works; it is this API that disagrees with it.

Repro

Walk the visual tree for a Button, compute its centre in root coordinates, and ask which elements are there:

var root = Microsoft.UI.Xaml.Window.Current?.Content as UIElement;

var topLeft = button.TransformToVisual(root).TransformPoint(new Point(0, 0));
var centre  = new Point(topLeft.X + button.ActualWidth  / 2,
                        topLeft.Y + button.ActualHeight / 2);

foreach (var e in VisualTreeHelper.FindElementsInHostCoordinates(centre, root))
{
    Console.WriteLine(e.GetType().Name);   // Frame, ContentPresenter, ContentPresenter
}

The button here is a Button subclass inside a Grid in a Page hosted by a Frame, but nothing about it is unusual — no transforms, no clipping, no custom hit-test logic.

Environment

Reproduces identically on both heads, with byte-identical output, so this looks like the shared Skia hit-testing path rather than anything platform-specific:

  • net10.0-desktop (Win32/Skia)
  • net10.0-browserwasm (Skia, Mono interpreter)

Uno.WinUI 7.0.0-dev.579, Uno.Sdk.Private, .NET 10.0.11.

Why it matters

FindElementsInHostCoordinates is the API you reach for when input is not behaving and you want to know what is on top at a point. Because it silently returns a plausible-looking but wrong answer rather than failing, it actively misleads: while debugging an unrelated input problem it pointed us straight at "the button is not hit-testable", which cost real time before event handlers showed input was fine all along. Automation and diagnostics built on it will be quietly wrong.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions