Skip to content

feat!: Move visual tree helpers to Uno.UI.Extras as VisualTreeExtensions - #26705

Open
Xiaoy312 wants to merge 32 commits into
masterfrom
dev/xygu/20261124/view-ext-methods-refactor
Open

Xiaoy312 wants to merge 32 commits into
masterfrom
dev/xygu/20261124/view-ext-methods-refactor

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: related to unoplatform/add-private#61 (a discussion, so nothing to close)

PR Type:

✨ Feature

What changed? 🚀

Since 7.0, the visual tree helpers (TreeGraph, FindFirstDescendant, FindFirstDescendantOrThrow, PrettyPrint, ...) are internal on WinAppSDK, so WinAppSDK heads can't call them anymore. This PR moves them into Uno.UI.Extras and makes them public on every target, WinAppSDK included.

  • ViewExtensions.visual-tree.cs and PrettyPrint.cs move from Uno.UI to Uno.UI.Extras, which already compiled them on WinAppSDK through links. The class is renamed Uno.UI.Extensions.VisualTreeExtensions; the namespace doesn't change, so extension-method calls compile as before. PrettyPrint keeps its name.
  • Uno.UI.ViewExtensions.EnumerateAllChildren(maxDepth) becomes VisualTreeExtensions.EnumerateRawDescendants(maxDepth), with no depth limit by default. It still includes the x:Load placeholders on Uno targets; on WinAppSDK it walks VisualTreeHelper.
  • The internal EnumerateAncestors becomes the public EnumerateVisualTreeAncestors, replacing GetVisualAncestry.
  • TryGetDpValue becomes public, and returns false instead of throwing when the value isn't of the requested type.
  • Removed: AsNativeView, the old ShowLocalVisualTree dump (including the Debug-only UIElement.ShowLocalVisualTree()), and the leftover unit-test mocks, including GetTopLevelParent, which threw on every target and took the public BinderReferenceHolder.GetInactiveChildViewBinders / GetInactiveChildInstancesOfType down with it.
  • Uno.UI can't reference Uno.UI.Extras, so its own callers now use internal, non-extension copies in VisualTreeHelper, named after the parent they follow: EnumerateVisualParents, EnumerateVisualTreeAncestors, EnumerateLogicalAncestors (renamed from EnumerateAncestors), EnumerateChildren, EnumerateDescendants and EnumerateRawDescendants. Behavior is unchanged for those callers, except that AutoSuggestBox and the simple-accessibility name aggregation no longer stop at 20 levels.
  • Uno.UI.ViewExtensions is removed. Its remaining FindFirstChild, which walked the raw child list, was only used by tests and samples; they now call VisualTreeExtensions.FindFirstDescendant, which walks the same descendants through VisualTreeHelper and exists on WinAppSDK too. The internal DependencyObjectExtensions.FindFirstChild goes the same way.
  • Tests and samples drop the WinAppSDK-only guards and usings that only existed because these helpers weren't available there (the per-platform FindFirstChild usings, the TabView sample's tree dump, the leak test's child walk, WindowHelper.WaitForLoaded).
  • The internal XamlHelper (tests only) also moves to Uno.UI.Extras, which already compiled it on WinAppSDK; Extras now grants InternalsVisibleTo to Uno.UI.UnitTests for it.
  • Now that they're public everywhere, both classes get a cleanup:
    • PrettyPrint: FormatObject is renamed FormatValue and the unused FormatData is removed; numbers are formatted with the invariant culture; zero no longer prints as an empty string in grid lengths and brush opacity; nullable annotations and doc comments on every method. New FormatTransform for render transforms.
    • VisualTreeExtensions: the OrThrow methods return T, require a reference type and throw InvalidOperationException; the child walk returns nothing for a null node instead of passing null to VisualTreeHelper; doc comments on every TreeGraph overload.
  • TreeGraph gets two public describers, DescribeLayout (the default, which now lists only values that differ from their defaults) and DescribeVisual (border, background, spacing, a control's current visual states), plus BeelineGraph, which prints the path from the root down to an element with the same describers. TreeGraph and its describers live in VisualTreeExtensions.TreeGraph.cs.
  • Docs: TreeGraph, its describers and BeelineGraph replace ShowLocalVisualTree in the visual tree debugging guide, the runtime-test guide points to FindFirstDescendant/FindFirstAncestor, and the 7.1 migration notes cover the changes.

Validation (local, Windows):

  • Build: Uno.UI, Uno.UI.Extras (Uno and WinAppSDK), Uno.UI.RemoteControl, Uno.UI.UnitTests, Uno.UI.RuntimeTests (Uno and WinAppSDK) and the SamplesApp (desktop and WinAppSDK heads).
  • Unit tests: Given_xLoad, Given_xBind_Binding, Given_ItemsControl, Given_ThemeResource, Given_StaticResource, Given_Explicit_Style, Given_ListViewBase, Given_Selector, Given_XamlReader, Given_AutomationPeerProviderTargets, FindName: all passed.
  • Runtime tests (Skia desktop):
    • classes touched by the move (Given_AutoSuggestBox, Given_ComboBox, Given_Flyout*, Given_FrameworkElement_EffectiveViewport, Given_ScrollViewer_ScrollChaining, Given_xLoad, TemplatedParentTests): 260 passed, 0 failed.
    • the 22 other classes whose FindFirstChild calls changed: 2450 passed, 0 failed.
    • Given_XamlParseContext_AlcResolution only runs on a net11.0 build: 12 of 14 pass; the 2 failing rows of When_OwningAppLacksAFrameworkKeyTheHostOverrides_Then_LoadTimeFallbackUsesTheOwningApp fail the same way on master.
    • the 4 tests whose lookups moved off FindFirstDescendantOrSelf last were rerun after that change: all passed.
    • after the VisualTreeExtensions cleanup: Given_ComboBox, TemplatedParentTests, Given_ContentPresenter, Given_FrameworkElement_EffectiveViewport: 411 passed, 0 failed.
    • after the describer presets: the two Given_ListViewBase tests that call the default TreeGraph(), TemplatedParentTests, Given_ContentPresenter: 296 passed, 0 failed.
  • PackageDiffIgnore.xml entries were not checked locally against the package diff.

PR Checklist ✅

Breaking changes (migration path in doc/articles/migrating-from-previous-releases.md, "Uno Platform 7.1"):

  • Uno.UI.Extensions.ViewExtensions and Uno.UI.Extensions.PrettyPrint move from Uno.UI.dll to Uno.UI.Extras.dll (same namespace; ViewExtensions renamed VisualTreeExtensions). Extension-method calls compile unchanged; class-qualified calls and using static need the new class name; binaries need recompiling.
  • EnumerateAllChildren → EnumerateRawDescendants (unlimited depth by default, selector overload removed); GetVisualAncestry → EnumerateVisualTreeAncestors().OfType<UIElement>(); AsNativeView removed.
  • PrettyPrint.FormatObject → FormatValue; PrettyPrint.FormatData removed.
  • FindFirstAncestorOrThrow / FindFirstDescendantOrThrow throw InvalidOperationException instead of Exception and require a reference type.
  • Uno.UI.ViewExtensions is removed; BinderReferenceHolder.GetInactiveChildViewBinders / GetInactiveChildInstancesOfType removed (they threw).

Downstream: uno.toolkit's LeakTest calls EnumerateAllChildren(maxDepth: 200) and needs to switch to EnumerateRawDescendants once a build with this change is available.

🤖 Generated with Claude Code

Xiaoy312 and others added 5 commits November 24, 2026 16:39
Uno.UI can't call the ViewExtensions helpers once they move to
Uno.UI.Extras, so it gets plain static copies named after the parent
they follow: EnumerateVisualParents, EnumerateVisualTreeAncestors,
EnumerateLogicalAncestors (renamed from EnumerateAncestors),
EnumerateChildren, EnumerateDescendants and EnumerateRawDescendants.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
FindName was its only caller.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GetTopLevelParent threw NotImplementedException on every target since
the native renderers were removed, so the public
BinderReferenceHolder.GetInactiveChildViewBinders and
GetInactiveChildInstancesOfType threw as soon as a tracked view was
active. Remove them with the other mocks (GetChildren(object),
FindFirstChild(FrameworkElement)).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TreeGraph covers it and is public in every build. Removes
ShowLocalVisualTree, ShowDescendants, their Get*Details helpers and the
Debug-only UIElement.ShowLocalVisualTree(); samples now call
TreeGraph. GetVisualAncestry goes with ViewExtensions.cs: Uno.UI uses
VisualTreeHelper.EnumerateVisualParents.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Moves ViewExtensions.visual-tree.cs (as VisualTreeExtensions.cs) and
PrettyPrint.cs from Uno.UI into Uno.UI.Extras, which already compiled
them on WinAppSDK through links. RemoteControl, which reached the
internal EnumerateChildren through Uno.UI, now walks the children
itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added area/build Categorizes an issue or PR as relevant to build infrastructure area/automation Categorizes an issue or PR as relevant to project automation kind/documentation labels Nov 24, 2026
Xiaoy312 and others added 5 commits November 24, 2026 17:22
Renames Uno.UI.Extensions.ViewExtensions in Uno.UI.Extras to
VisualTreeExtensions and makes it public on WinAppSDK too, where 7.0
had made it internal.

- EnumerateAllChildren(maxDepth) becomes EnumerateRawDescendants, with
  no depth limit by default; on WinAppSDK it walks VisualTreeHelper.
- The internal EnumerateAncestors becomes the public
  EnumerateVisualTreeAncestors, replacing GetVisualAncestry.
- TryGetDpValue becomes public, and returns false instead of throwing
  when the value isn't a T.
- AsNativeView is removed.
- Uno.UI.ViewExtensions (FindFirstChild) is now internal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TreeGraph is public on every target now, including WinAppSDK.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ShowLocalVisualTree is gone; TreeGraph is public on every target in
Uno.UI.Extras.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
TreeGraph, PrettyPrint and EnumerateRawDescendants are public on
WinAppSDK now. The TabView sample's tree dump keeps a guard only on the
Uno-internal layouter detail, and drops its dead native-view details;
the leak test walks the same descendants on every target.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Xiaoy312
Xiaoy312 force-pushed the dev/xygu/20261124/view-ext-methods-refactor branch from 26ddb64 to a16c5c5 Compare November 24, 2026 22:22
Xiaoy312 and others added 3 commits November 24, 2026 17:30
Only the test projects use it, and Uno.UI.Extras already compiled it
on WinAppSDK through a link. Uno.UI.UnitTests gets access to the
Extras internals for it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
It's public in Uno.UI.Extras on every target, so WindowHelper no longer
needs a different FindFirstChild per platform.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 248951 found UI Test snapshots differences: skia-linux-screenshots: 245, skia-windows-screenshots: 274

Details
  • skia-linux-screenshots: 245 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_Showcase.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • AnimatedBackVisualSourceSamplePage.png
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • Accessibility_Showcase.png
    • AnimatedVisualsTestbedPage.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • AppWindowTitleBar Properties.png-dark
    • AppWindowTitleBar Properties.png
    • Basics.png-dark
  • skia-windows-screenshots: 274 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedVisualsTestbedPage.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • AnimatedVisualsTestbedPage.png-dark
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • AnimatedBackVisualSourceSamplePage.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • Accessibility_Showcase.png-dark
    • Basics.png-dark
    • Basics.png

Xiaoy312 and others added 5 commits November 24, 2026 19:18
Removes Uno.UI.ViewExtensions and its FindFirstChild, which walked the
raw child list. Tests and samples now call
DependencyObjectExtensions.FindFirstChild, which walks VisualTreeHelper
in the same order and is also compiled into Uno.UI.Extras on WinAppSDK,
so the WINAPPSDK-only usings that picked the right FindFirstChild per
platform collapse to one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
It searches the whole subtree and returns the element itself first, so
the name now says so and pairs with VisualTreeExtensions.FindFirstDescendant.
Its unused childLevelLimit and includeCurrent parameters go; the two
includeCurrent: false callers use FindFirstDescendant instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Calls whose receiver type can never be the requested type now use the
public VisualTreeExtensions.FindFirstDescendant, which walks the same
descendants without checking the root. FindFirstDescendantOrSelf stays
where the receiver itself could be a match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
None of these roots can be the element searched for at runtime. The
TextBox caret test also gets a GetCaretPopups helper for its repeated
popup query.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every caller now uses VisualTreeExtensions.FindFirstDescendant.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Xiaoy312
Xiaoy312 marked this pull request as ready for review November 25, 2026 00:46
@mergify

mergify Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

The class is removed, not made internal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the area/skia ✏️ Categorizes an issue or PR as relevant to Skia label Nov 25, 2026
FindFirstChild is gone; FindFirstDescendant and FindFirstAncestor work
on every target with a single using.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@unodevops

Copy link
Copy Markdown
Contributor

Xiaoy312 and others added 3 commits November 24, 2026 20:10
It prints the value itself, except for dependency objects, which print
as their type name. FormatData, which nothing used, is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Zero no longer prints as an empty string in grid lengths, grid
  definitions and brush opacity.
- Numbers are formatted with the invariant culture, so a decimal comma
  can't collide with the separators.
- Enables nullable annotations, documents each method, fixes the
  corner order in FormatCornerRadius's comment and drops unused usings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nventive-devops

Copy link
Copy Markdown
Contributor

The build 248964 found UI Test snapshots differences: skia-linux-screenshots: 203, skia-windows-screenshots: 272

Details
  • skia-linux-screenshots: 203 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • AnimatedBackVisualSourceSamplePage.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Accessibility_Showcase.png
    • AnimatedVisualsTestbedPage.png
    • AppWindowTitleBar Properties.png
    • AutomationProperties_AutomationId.png-dark
    • Accessibility_Showcase.png-dark
    • AppWindowTitleBar Properties.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • Basics.png-dark
    • Basics.png
    • CornerRadiusControls.png-dark
  • skia-windows-screenshots: 272 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AnimatedBackVisualSourceSamplePage.png
    • AppWindowTitleBar Properties.png-dark
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • ColorPickerSample.png-dark
    • ColorPickerSample.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • Accessibility_Showcase.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • AnimatedBackVisualSourceSamplePage.png-dark
    • Basics.png-dark
    • Basics.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png

Xiaoy312 and others added 9 commits November 24, 2026 20:44
- The OrThrow methods all return T, take T : class (or FrameworkElement
  when matching by name) and throw InvalidOperationException.
- EnumerateChildren returns nothing for a null node instead of calling
  VisualTreeHelper with null.
- TreeGraph's default details format numbers with the invariant culture.
- Uses DependencyObject instead of the _View alias, documents every
  TreeGraph overload, and drops unused usings and an empty #if block.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Formats each transform kind compactly (Translate, Scale, Rotate, Skew,
Composite, Matrix, groups), with "(identity)" when it changes nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
DescribeLayout is TreeGraph's default and now only lists values that
differ from their defaults (grid cell, constraints, alignment, spacing,
opacity, Collapsed). DescribeVisual shows border, background, spacing
and a control's current visual states. Both can be passed as
describeProperties.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
VisualTreeExtensions.TreeGraph.cs holds TreeGraph, the DescribeLayout
and DescribeVisual presets and their helpers; the tree walks stay in
VisualTreeExtensions.cs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Prints the element's ancestors root first, one per line and indented
like TreeGraph, with the same describers, to see why an element is
sized or placed the way it is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Commented out like the other optional details.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@unodevops

Copy link
Copy Markdown
Contributor

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 248975 found UI Test snapshots differences: skia-linux-screenshots: 208, skia-windows-screenshots: 278

Details
  • skia-linux-screenshots: 208 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_Showcase.png
    • AutomationProperties_StructureAndProps.png-dark
    • AutomationProperties_StructureAndProps.png
    • BenchmarkDotNet.png-dark
    • BenchmarkDotNet.png
    • BitmapIcon_Foreground.png-dark
    • BitmapIcon_Foreground.png
    • Border_CornerRadius_Binding.png-dark
    • Border_CornerRadius_Binding.png
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • ComboBox_MaxDropdownHeight.png-dark
    • ComboBox_MaxDropdownHeight.png
    • CornerRadiusControls.png-dark
    • CornerRadiusControls.png
    • AppWindowTitleBar Properties.png-dark
    • AppWindowTitleBar Properties.png
    • AutomationProperties_AutomationId.png-dark
    • AutomationPropertiesExtensions_Role.png-dark
    • AutomationProperties_AutomationId.png
  • skia-windows-screenshots: 278 changed over 2504

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • Accessibility_Showcase.png-dark
    • AnimatedVisualsTestbedPage.png
    • AutomationProperties_AutomationId.png-dark
    • AutomationProperties_AutomationId.png
    • AutomationProperties_StructureAndProps.png
    • BenchmarkDotNet.png-dark
    • BreadcrumbBarPage.png-dark
    • BreadcrumbBarPage.png
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • ClipboardTests.png-dark
    • ClipboardTests.png
    • AnimatedVisualsTestbedPage.png-dark
    • AppWindowTitleBar Properties.png-dark
    • AutomationProperties_StructureAndProps.png-dark
    • BasicAcrylicBrushTest.png-dark
    • BasicAcrylicBrushTest.png
    • Border_CornerRadius_BorderThickness.png-dark
    • Border_CornerRadius_BorderThickness.png
    • AppWindowTitleBar Properties.png

@ajpinedam ajpinedam left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation area/build Categorizes an issue or PR as relevant to build infrastructure area/skia ✏️ Categorizes an issue or PR as relevant to Skia kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants