Skip to content

Check panel membership in Windows ContentButton reparenting device test - #40692

Merged
kubaflo merged 2 commits into
mainfrom
simonrozsival-fix-windows-contentbutton-reparenting
Nov 27, 2026
Merged

kubaflo merged 2 commits into
mainfrom
simonrozsival-fix-windows-contentbutton-reparenting

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Target Branch

This PR is for Initial base
New features, API changes, or .NET 12 work (including .NET 12 fixes) main
.NET 11 servicing fixes net11, for review
Older servicing, release integration, infrastructure, or documentation The branch designated for that work

For .NET 11 fixes, only a maintainer retargets the approved PR to the active
inflight lane and merges it after CI validates that final base. Do not merge
individual fixes directly into net11; agents must not retarget or merge.

Description of Change

ContentButtonControlTests.ReparentingChildDuringHandlerCreationKeepsItInNewParent (added with the native ContentButton in #39762) fails on Windows only, packaged and unpackaged, at its last assertion:

Assert.Same() Failure: Values are not the same instance
Expected: ContentPanel { ..., ActualSize = <0, 0>, ... }
Actual:   null

It never failed on main's CI because Windows device tests have not built there since #36581 (#40666 fixes that build).

The test creates its handlers with CreateHandler, which never adds them to a window, so none of the WinUI elements are in the live tree. In the original label's HandlerChanged callback it swaps the button's content and moves the label into a ContentView. The last assertion asked a WinUI parent query whether the label's TextBlock is parented to the destination ContentPanel:

  1. The original helper used VisualTreeHelper.GetParent, which returns null for any element outside the live tree ("Don't return the parent unless we're in the live tree"). So that failure didn't show anything about the product.
  2. This PR's first commit switched to FrameworkElement.Parent. That still returned null on CI (maui-pr-devicetests 1702098 on [Validation only - do not merge] #33561 + #40666 #40667, with product code identical to main). Microsoft's docs say Parent "can be null if an object was instantiated, but is not attached to an object that eventually connects to a page object root".

Static tracing of the product path finds no step that detaches the TextBlock or replaces the label's handler. The guarded ContentButtonHandler.MapContent returns before touching the label once the content has changed, and ContentViewHandler.UpdateContent adds the TextBlock to the destination ContentPanel. Still, a parent query that reads null off-tree can't tell a reporting gap from a real product bug.

The test now checks the invariant directly on Windows instead of asking WinUI for a parent:

  • the label keeps the platform view it had right after the move;
  • the destination ContentPanel's children contain that view (checked by enumerating its children and comparing references);
  • the button's ContentPanel does not contain it.

A WinUI element can belong to only one parent, so this is as strict as the previous parent check. Each assertion message records the view's Parent, its VisualTreeHelper parent, and both panels' Content and children, captured both right after the move and at the end. If the product is wrong, the failure shows where the view went. Android (View.Parent) and iOS (Superview) keep the parent assertion, which works outside a window.

Validation

  • Windows can't be built or run on the macOS dev machine. The new Windows code was type-checked against the WinUI 2.3.9 reference assemblies in a scratch net10.0-windows10.0.19041.0 project, with stubs for the internal MAUI types (dotnet build: succeeded; a deliberate misspelling was reported as CS1061). The file was also compiled with each of ANDROID, IOS, MACCATALYST and WINDOWS defined: the only errors were missing references from compiling outside the device-test project, with no syntax, preprocessor or missing-name errors in the new code.
  • The Windows device-test result needs CI (maui-pr-devicetests) on a branch that includes the build fix from Fix the four build breaks on main (RS1038, CS0260, IL2121, Essentials Windows CS0117) #40666.

Issues Fixed

Fixes a Windows device-test failure in ContentButtonControlTests (no separate issue). It was seen in maui-pr-devicetests builds 1701680 and 1702098 (#40667) and 1701815 (#40666).

Let AI finish this PR

  • Let the MAUI agent address review feedback and fix remaining issues on this PR. Maintainers still decide whether it is merged. For PRs from forks, the agent opens a follow-up PR that keeps your commits.

ReparentingChildDuringHandlerCreationKeepsItInNewParent failed on
Windows because its GetPlatformParent helper used
VisualTreeHelper.GetParent. WinUI's public GetParent returns null for any
element that is not in the live visual tree, and the test creates its
handlers without adding them to a window. The original label's TextBlock
is a child of the destination ContentPanel, but the helper could not see
it.

Read FrameworkElement.Parent instead. For a panel child it is the panel,
whether or not the panel is loaded, and the helper still confirms that
the panel's CachedChildren contains the element.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 06:58
@github-actions

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

simonrozsival added a commit that referenced this pull request Nov 27, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

🔵 Needs a closer look

The fix relies on unverified WinUI FrameworkElement.Parent behavior for detached panel children, requiring the updated reparenting test to pass in packaged and unpackaged Windows device-test CI.

No open issues 🎉

What changed in this PR

This PR corrects the Windows parent lookup in the ContentButton reparenting device test introduced in #39762. It changes only test code, allowing parent assertions to work when handlers are not attached to a window.

Changes:

  • Replaces VisualTreeHelper.GetParent with FrameworkElement.Parent on Windows.
  • Checks MauiPanel.CachedChildren to confirm panel membership.
  • Leaves Android and Apple platform behavior unchanged.
File Description
src/​Controls/​tests/​DeviceTests/​Elements/​ContentButton/​ContentButtonControlTests.cs Updates the Windows helper to verify parent membership outside the live visual tree.

Review effort: Balanced

@kubaflo

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot 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.

Expert Review — No findings

Reviewed commit 27e9b4a.

@github-actions

This comment has been minimized.

@simonrozsival

Copy link
Copy Markdown
Member Author

The fix is present in the tested source, but the targeted validation still fails:

In #40667's selected Windows device build 1702160, both Controls.DeviceTests-packaged and Controls.DeviceTests-unpackaged execute the Button category with 26 passed / 1 failed / 0 skipped. The failure is ContentButtonControlTests.ReparentingChildDuringHandlerCreationKeepsItInNewParent:

Assert.Same() Failure
Expected: ContentPanel
Actual: null

I checked the actual synthetic build source 32c19b4e3bac41dd550b8a3b09d35603abeff0c6: its GetPlatformParent includes this PR's FrameworkElement.Parent / MauiPanel.CachedChildren implementation. The recorded test merge 8f55e68dd916a87a69adbc8a849976b76f93ed19 includes #40667 head 6284ba719ec5a1bb1bcd8270794c1138f11c4ca3, which merged this fix.

Evidence comes from the actual uploaded testResults.xml files in Helix job 9cb3decb-93b0-4d5a-a2c7-f7b294ef8305, not the AzDO test-run summary (which misleadingly remains InProgress with zero passes). These are real assertion failures, not a crash inferred from the normal WinUI exit code -1. The fix needs further investigation.

CI showed that the previous FrameworkElement.Parent-based helper still
returned null on Windows. These handlers are never added to a window,
and WinUI parent queries do not reliably report parents outside the live
tree, so they cannot tell a reporting gap from a real product bug.

On Windows, assert the invariant directly: the original label keeps the
platform view it had when it moved, the destination ContentPanel's
children contain that view, and the button's ContentPanel does not. Each
assertion message records the view's Parent, its VisualTreeHelper parent,
and both panels' Content and children, both right after the move and at
the end, so a failure identifies where the view went.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 27, 2026 09:45
@simonrozsival simonrozsival changed the title Fix Windows ContentButton reparenting device test parent lookup Check panel membership in Windows ContentButton reparenting device test Nov 27, 2026
simonrozsival added a commit that referenced this pull request Nov 27, 2026
…idation

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

🔵 Needs a closer look

The revised WinUI off-tree assertions lack packaged and unpackaged Windows device-test results needed to confirm they resolve the observed runtime failure.

No open issues 🎉

Review effort: Balanced

@kubaflo

This comment has been minimized.

@kubaflo

This comment has been minimized.

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Selected Tests

@kubaflo — AI-selected UI tests and device tests (GPT-6.2 Sol + MAI Code 2) for commit aa0f9e5b.

Result FAILED Platforms Windows Tests 0 UI, 1 device Commit aa0f9e5b


🧪 Test selection — click to expand
Suite Result Selected Build
UI tests ➖ nothing to run none —
Device tests ❌ failed 1 of 105 units maui-pr-devicetests #1702365
🧪 UI tests — nothing to run

ℹ️ The AI found no changes relevant to UI tests, so no maui-pr-uitests run was queued.

GPT-6.2 Sol: No UI tests are needed because the PR only changes a device test.
MAI Code 2: Device-test-only Windows ContentButton assertion change; no UI tests, and runs Windows Controls.Button device tests.

🧪 Running — nothing

No UI tests run for this PR.

🧪 Device tests — Controls.Button on Windows

❌ maui-pr-devicetests #1702365 failed — 1 job failed. See Results below.

GPT-6.2 Sol: Run Windows Controls.Button device tests to validate the revised ContentButton reparenting assertions.
MAI Code 2: Run the Windows Controls.Button device tests for the ContentButton reparenting assertion update.

🧪 Ran — 1 category on Windows

Platform Categories
Windows Controls.Button
📊 Results — failed: 0 passed, 1 failed of 1 jobs

🔗 All test results · Build logs

Job Result
net12.0 Windows Helix Tests - Build Build Device Tests (Windows) ❌ failed
⏭️ Skipped — what neither suite runs

UI tests — 77 categories, 4 platforms

Platforms not run: Android, iOS, MacCatalyst, Windows

Each skipped platform and category is listed as a maui-pr-uitests (skipped) … status on this commit. Use /azp run maui-pr-uitests for the full suite.

Device tests — 104 categories, 3 platforms

Platforms not run: Android, iOS, MacCatalyst

Categories not run: Controls.Accessibility, Controls.Animations, Controls.Application, Controls.Behavior, Controls.Border, Controls.BoxView, Controls.CarouselView, Controls.CheckBox, Controls.CollectionView, Controls.Compatibility, Controls.ContentView, Controls.DatePicker, Controls.Dispatcher, Controls.Editor, Controls.Element, Controls.Entry, Controls.FlexLayout, Controls.FlyoutPage, Controls.Frame, Controls.Gesture, Controls.HybridWebView, Controls.Image, Controls.Label, Controls.Layout, Controls.Lifecycle, Controls.Map, Controls.Mapper, Controls.Memory, Controls.MenuFlyout, Controls.Modal, Controls.NavigationPage, Controls.Page, Controls.PageTransitions, Controls.Path, Controls.Picker, Controls.RadioButton, Controls.RefreshView, Controls.ScrollView, Controls.SearchBar, Controls.Shape, Controls.Shell, Controls.Slider, Controls.SwipeView, Controls.Switch, Controls.TabbedPage, Controls.TemplatedView, Controls.TextInput, Controls.Toolbar, Controls.View, Controls.VisualElement, Controls.VisualElementTree, Controls.WebView, Controls.Window, Controls.WindowOverlay, Controls.Xaml, Core.ActivityIndicator, Core.Animation, Core.Application, Core.Border, Core.BoxView, Core.Button, Core.CheckBox, Core.ContentView, Core.DatePicker, Core.Dispatcher, Core.Editor, Core.Element, Core.Entry, Core.FlowDirection, Core.FlyoutView, Core.Fonts, Core.Formatting, Core.Graphics, Core.GraphicsView, Core.Image, Core.ImageButton, Core.ImageSource, Core.IndicatorView, Core.Label, Core.Layout, Core.Lifecycle, Core.MauiContext, Core.Memory, Core.NavigationPage, Core.Page, Core.Picker, Core.ProgressBar, Core.RadioButton, Core.RefreshView, Core.ScrollView, Core.SearchBar, Core.ShapeView, Core.Slider, Core.Stepper, Core.SwipeView, Core.Switch, Core.TimePicker, Core.View, Core.WebView, Core.Window, Core.WindowOverlay, Graphics, Essentials, BlazorWebView

Each skipped platform and project is listed as a maui-pr-devicetests (skipped) … status on this commit. Use /azp run maui-pr-devicetests for the full suite.

🤖 Why these tests — AI rationale (GPT-6.2 Sol + MAI Code 2)

UI tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android — —
iOS — —
MacCatalyst — —
Windows — —

GPT-6.2 Sol — No UI tests are needed because the PR only changes a device test.

  • ContentButtonControlTests.cs is a device test.
  • No product code or UI test infrastructure changed.

MAI Code 2 — Device-test-only Windows ContentButton assertion change; no UI tests, and runs Windows Controls.Button device tests.

  • The only change is in src/Controls/tests/DeviceTests/Elements/ContentButton/ContentButtonControlTests.cs, so it does not affect the UI test app or product UI behavior.
  • The test is categorized as TestCategory.Button and the new assertions are guarded by #if WINDOWS.
  • Windows Controls.Button covers the changed ContentButton reparenting device test; no Android, iOS, or Mac Catalyst coverage is needed.

Device tests

Each model chose independently; every test that runs was selected by at least one of them.

Platform GPT-6.2 Sol MAI Code 2
Android — —
iOS — —
MacCatalyst — —
Windows Controls.Button Controls.Button

GPT-6.2 Sol — Run Windows Controls.Button device tests to validate the revised ContentButton reparenting assertions.

  • ContentButtonControlTests.cs is tagged Button; its new assertions check WinUI panel membership.
  • The changes are guarded by #if WINDOWS, so other platforms and device categories are excluded.

MAI Code 2 — Run the Windows Controls.Button device tests for the ContentButton reparenting assertion update.

  • ContentButtonControlTests is a device-test file marked [Category(TestCategory.Button)].
  • All added membership and diagnostic assertions are Windows-specific and validate off-tree WinUI panel children.
  • The diff changes test assertions only; no handler/product or shared device-test infrastructure warrants Core or a full run.

Generated by /review run-tests. A targeted run is a fast signal, not full-suite certification.

@github-actions github-actions Bot 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.

Expert Review — No more findings

Reviewed commit aa0f9e5.

@kubaflo
kubaflo merged commit 94ea8f1 into main Nov 27, 2026
33 of 54 checks passed
@kubaflo
kubaflo deleted the simonrozsival-fix-windows-contentbutton-reparenting branch November 27, 2026 10:31
kubaflo added a commit that referenced this pull request Nov 28, 2026
…40767)

<!-- Please let the below note in for people that find this PR -->
> [!NOTE]
> Are you waiting for the changes in this PR to be merged?
> It would be very helpful if you could [test the resulting
artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from
this PR and let us know in a comment if this change resolves your issue.
Thank you!

<!--
Open .NET 11 fix PRs against net11 for review; target main for
next-major features.
After approval, a maintainer manually retargets the fix PR to the active
inflight
branch and merges it directly there. Do not merge individual fixes into
net11.
Bots must not retarget or merge. Candidate integration into net11 and
release/*
changes are separate, explicitly coordinated release work.
-->

### Target Branch

| This PR is for | Initial base |
| --- | --- |
| New features, API changes, or .NET 12 work (including .NET 12 fixes) |
`main` |
| .NET 11 servicing fixes | `net11`, for review |
| Older servicing, release integration, infrastructure, or documentation
| The branch designated for that work |

- [x] I selected the applicable base branch using the [contribution
guide](https://github.com/dotnet/maui/blob/main/.github/CONTRIBUTING.md#choose-your-pr-base-before-starting).

For .NET 11 fixes, only a maintainer retargets the approved PR to the
active
inflight lane and merges it after CI validates that final base. Do not
merge
individual fixes directly into `net11`; agents must not retarget or
merge.

### Description of Change

Correct the Windows Shell flyout-clipping device test's native-layout
prerequisites without changing product behavior, skipping tests, adding
retries, or weakening its regression assertions.

Stop retaining the first `DataTemplate` instance. WinUI can prepare
template instances outside the live flyout or replace them. A handler
alone does not establish visual-tree membership or completed
arrangement. Select the loaded, positively arranged flyout item from the
actual Shell visual tree, then run the unchanged non-null clip and exact
rounded-width assertions. The readiness wait does not wait for the
assertion to become true.

Existing-fix search covered open and recently merged PRs. #40717
concerns custom TitleBar overlap, not flyout-template selection. #40692
addresses a different ContentButton reparenting test, and #40727
addresses Windows CarouselView position updates; neither is duplicated
here.

#### Validation and scope correction

- **Baseline red = main 1703707**, head `34964bfc72`. Shell fails in
both packaged attempts and the second unpackaged attempt; the first
unpackaged attempt passes. Raw first-attempt logs: 787/788;
second-attempt logs: 962/960. Both Windows Shell jobs also fail in
migration PR #40661 build 1703676 (logs 757/766).
- **Fix = PR CI 1703831** at `1e894622fe`: Windows Shell category **92
passed, 0 failed, 0 skipped in each mode**, logs
[757](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1703831/logs/757?api-version=7.1)
and
[758](https://dev.azure.com/dnceng-public/public/_apis/build/builds/1703831/logs/758?api-version=7.1).
The unchanged Shell patch compiled and executed on Windows in that CI
run.
- The initial commit also attached the ContentButton replacement test to
a native window. **CI disproved that attempted fix**: build 1703831 Core
logs 621/625 still report expected frame `{X=5 Y=5 Width=170
Height=80}`, actual zero. That Button change has been reverted in a
normal follow-up commit; the net PR diff now contains only
`ShellTests.Windows.cs`.
- Static tracing of the Button path confirms `SetVirtualView(second)`
updates the panel's `CrossPlatformLayout`, maps the expected replacement
native content, and measures its requested size.
`ContentButtonLayout.Arrange` would assign the presented content's
managed frame through `StubBase.Arrange`; the current failure logs do
not prove why that arrange path is not reflected in the frame. No
speculative timing workaround or product fix is included.
- `git diff --exit-code 34964bf --
src/Core/tests/DeviceTests/Handlers/ContentButton/ContentButtonWindowsTests.Windows.cs`
— **passed**, proving the Button file is restored exactly to the
baseline.
- `git diff --check` — **passed**.
- Initial local `dotnet build Microsoft.Maui.BuildTasks.slnf -v:q` —
**passed**. Initial `dotnet format whitespace Microsoft.Maui.sln
--no-restore --include
src/Core/tests/DeviceTests/Handlers/ContentButton/ContentButtonWindowsTests.Windows.cs
src/Controls/tests/DeviceTests/Elements/Shell/ShellTests.Windows.cs
--verbosity quiet` — **passed**.
- Initial Windows cross-host build attempts on macOS were blocked by
native tooling: Core's Windows-only build reached `MakePri.exe` and
failed with exec format error; Controls' fallback with
`AppxGeneratePriEnabled=false` reached the native WinUI XAML compiler
and failed without `output.json`. No local Windows compilation or
runtime success is claimed.
- Revert/restore runtime verification **not run (no Windows host)**. The
Button source restoration is mechanically verified; updated PR CI is
requested separately.

CarouselView native-centering and HybridWebView coexistence failures did
not repeat across baseline attempts and passed the migration PR
comparison, so they remain unchanged. The recurrent NavigationPage crash
had `SettingTitleIconImageSourceDoesntCrash` in flight, but no dump and
an unproven cause; it is neither patched speculatively nor classified as
infrastructure. PageTransitions is outside this PR's scope.

### Issues Fixed

<!-- Please make sure that there is a bug logged for the issue being
fixed. The bug should describe the problem and how to reproduce it. -->

Addresses the recurring Windows Shell flyout-clipping device-test
failure in builds 1703707 and 1703676. No separate tracking issue;
preserves regression coverage for #19542. The ContentButton replacement
failure remains unresolved and is no longer changed by this PR.

### Let AI finish this PR

- [ ] **Let the MAUI agent address review feedback and fix remaining
issues on this PR.** Maintainers still decide whether it is merged. For
PRs from forks, the agent opens a follow-up PR that keeps your commits.

<!--
Verify the target branch follows the release workflow in
docs/ReleaseBranchWorkflow.md.
Infrastructure and documentation changes should target the branch where
they apply.
-->

---------

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants