Repository navigation
Check panel membership in Windows ContentButton reparenting device test - #40692
Conversation
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>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🔵 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.GetParentwithFrameworkElement.Parenton Windows. - Checks
MauiPanel.CachedChildrento 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
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Expert Review — No findings
Reviewed commit 27e9b4a.
This comment has been minimized.
This comment has been minimized.
|
The fix is present in the tested source, but the targeted validation still fails: In #40667's selected Windows device build 1702160, both I checked the actual synthetic build source Evidence comes from the actual uploaded |
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>
…idation Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Selected Tests
🧪 Test selection — click to expand
🧪 UI tests — nothing to runℹ️ The AI found no changes relevant to UI tests, so no GPT-6.2 Sol: No UI tests are needed because the PR only changes a device test. 🧪 Running — nothingNo UI tests run for this PR. 🧪 Device tests —
|
| 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.
There was a problem hiding this comment.
Expert Review — No more findings
Reviewed commit aa0f9e5.
…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>
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
mainnet11, for reviewFor .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 nativeContentButtonin #39762) fails on Windows only, packaged and unpackaged, at its last assertion: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'sHandlerChangedcallback it swaps the button's content and moves the label into aContentView. The last assertion asked a WinUI parent query whether the label'sTextBlockis parented to the destinationContentPanel: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.FrameworkElement.Parent. That still returnednullon CI (maui-pr-devicetests1702098 on [Validation only - do not merge] #33561 + #40666 #40667, with product code identical tomain). Microsoft's docs sayParent"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
TextBlockor replaces the label's handler. The guardedContentButtonHandler.MapContentreturns before touching the label once the content has changed, andContentViewHandler.UpdateContentadds theTextBlockto the destinationContentPanel. 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:
ContentPanel's children contain that view (checked by enumerating its children and comparing references);ContentPaneldoes 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, itsVisualTreeHelperparent, and both panels'Contentand 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
net10.0-windows10.0.19041.0project, with stubs for the internal MAUI types (dotnet build: succeeded; a deliberate misspelling was reported as CS1061). The file was also compiled with each ofANDROID,IOS,MACCATALYSTandWINDOWSdefined: 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.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 inmaui-pr-devicetestsbuilds 1701680 and 1702098 (#40667) and 1701815 (#40666).Let AI finish this PR