Skip to content

[Windows] Fix Border clipping for transformed content - #37424

Merged
kubaflo merged 20 commits into
inflight/currentfrom
jfversluis-fix-border-clipping-windows
Aug 20, 2026
Merged

kubaflo merged 20 commits into
inflight/currentfrom
jfversluis-fix-border-clipping-windows

Conversation

@jfversluis

@jfversluis jfversluis commented Aug 14, 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!

Fixes #17523

Root cause

Windows attached the Border's CompositionGeometricClip directly to the content visual while authoring the geometry in the parent ContentPanel coordinate space. Scale, rotation, and translation therefore transformed the clip together with the content instead of keeping the Border aperture stationary.

Fix

  • Place Border content inside a Border-only stationary native clip host and attach the geometric clip to that host.
  • Route cross-platform measure invalidation to both native layers while preserving WinUI's cached subtree measure on unrelated parent layout passes.
  • Avoid re-entering measure from arrange when a layout owner changes; the normal invalidated measure pass remains authoritative.
  • Preserve the cross-platform arranged size through the native clip host, including detached and reconnected layout-owner transitions.
  • Cache stable composition and rectangular bounds clip geometry, rebuilding only when geometry inputs change.
  • Tear down layout owners, hosted content, stroke references, and cached clip state when the handler disconnects, after derived handler disconnect hooks have observed the intact platform view.
  • Safely ignore late invalidation after handler disconnect and synchronize direct or reconnect-driven layout-owner changes with the clip host.
  • Preserve current cross-parent content reparenting while clearing stale clip-host ownership when content moves Border → Border, Border → generic MauiPanel, or back again.
  • Handle zero-by-infinite WinUI measure constraints without invoking cross-platform layout.
  • Keep layout invalidation flowing for initial asynchronous image loads and runtime content-size, FontSize, and Padding changes without requiring an outer window resize.
  • Preserve explicit Border sizing, stroke/shadow behavior, nested layout clipping, content replacement, custom handler activation and mapper customization, shape removal, and accessibility behavior.
  • Clamp stroke-inset geometry to nonnegative dimensions and preserve an explicitly empty aperture when the stroke consumes all available content space, including rounded shapes.
  • Clear stale clipping geometry whenever either arranged dimension is non-positive.
  • Remove the obsolete nested LayoutPanel clip exception because the XAML rectangular clip and Border composition clip now live on separate visuals.
  • Update the three affected WinUI Image AspectFill baselines for the stationary clip host's one-pixel antialiased inner edge; image content remains pixel-identical.

This is an implementation-only Windows fix; it adds no public APIs.

Before / after video proof

Before — issue author's attached reproduction, minimally retargeted to the current Windows TFM: transformed image content escapes the stationary ellipse, rounded rectangle, and triangle apertures as image scale changes.

issue-17523-before.mp4

After — final reviewed PR gallery build using the exact BorderResizeContent source scenario: the same scale interaction changes the image while each Border aperture remains stationary and correctly clips its content.

issue-17523-after-final-review.mp4

Both recordings use a 1280×720 window. Pixel analysis of the recorded scale-4 frames detected transformed image pixels outside the three Border regions before the fix and 0 outside after the fix.

Validation

  • Windows Border device tests: 38 passed, 0 failed, 0 skipped, 0 errors.
  • Added coverage for scale, rotation, translation, combined transforms, shadows, nested layouts, initial asynchronous image rendering, runtime FontSize and Padding, explicit sizing, content replacement, shape removal, disconnect/reconnect, derived disconnect ordering, teardown cleanup, direct layout-owner changes, derived handlers, clip ownership, cross-host and generic-parent reparenting, composition and bounds clip reuse, zero-by-infinite constraints, stroke-consuming zero-interior geometry, rounded empty apertures, cross-platform arranged-size propagation, automation, and layout-cache reuse.
  • Exact final BorderResizeContent.xaml gallery proof ran without resizing the window:
    • Image scale 1 → 4 changed 14,673 pixels inside the Border shapes and 0 outside.
    • Font size 40 → 120 changed 11,584 pixels inside the Border shapes and 0 outside.
    • All images rendered on initial load.
  • The repository's production MagickNetVisualComparer passes all three updated WinUI Image AspectFill snapshots at the default 0.005 RMS threshold. The accepted delta is confined to the one-pixel Border edge with zero changed pixels in the image interior.
  • Multiple independent MAUI expert, adversarial, and layout/performance reviews completed with no remaining actionable findings.

@jstedfast, could you please test the PR artifacts against the original BorderResizeContent reproduction and confirm that initial rendering, transformed clipping, runtime font-size changes, and resizing now behave correctly?

Ahamed-Ali and others added 2 commits August 13, 2026 23:08
### Description of Change
This pull request makes a minor update to the UI test pipeline
configuration

- Pipeline configuration simplification:
* Removed the **duplicate** code that set the `$deviceType` variable and
appended the `--skin` argument to the test command in
`eng/pipelines/common/ui-tests-steps.yml`.


The same code was already added at [line
133](https://github.com/dotnet/maui/blob/main/eng/pipelines/common/ui-tests-steps.yml#L133)
as part of [PR #33409](#33409).

The duplicate code was also added at [line
156](https://github.com/dotnet/maui/blob/main/eng/pipelines/common/ui-tests-steps.yml#L156)
as part of [PR #31631](#31631).
Clip Border content through a stationary native host so child transforms do not transform the clip geometry. Preserve layout invalidation, explicit sizing, reconnect behavior, and custom handler activation.

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

Copilot-Session: 37b8c9a3-5a3c-427e-8006-99c04b5dbd4d
Copilot AI lite review requested due to automatic review settings August 14, 2026 11:25
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.sh | bash -s -- 37424

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/maui/main/eng/scripts/get-maui-pr.ps1) } 37424"

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

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.

Pull request overview

This PR fixes Windows Border clipping when the Border’s content is transformed (scale/rotation/translation) by moving the CompositionGeometricClip to a stationary native “clip host” visual so the clip aperture remains in Border coordinates rather than being transformed with the content.

Changes:

  • Introduces a ContentPanelClipHost inside ContentPanel and attaches the composition clip to that host instead of the content visual.
  • Updates the Windows BorderHandler to enable the clip host, route CrossPlatformLayout updates to both panel and host, and clean up on disconnect/content changes.
  • Adds extensive Windows Border device test coverage for transforms, async image load rendering, runtime layout changes (FontSize/Padding), and handler/content lifecycle cases.
Show a summary per file
File Description
src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt Records new protected override API entry for BorderHandler.DisconnectHandler(ContentPanel).
src/Core/src/Platform/Windows/LayoutPanel.cs Removes special-case clip suppression so ClipsToBounds always applies a XAML rectangle clip.
src/Core/src/Platform/Windows/ContentPanel.cs Adds clip-host panel, routes content into the host, and moves composition clip application to the host visual.
src/Core/src/Handlers/Border/BorderHandler.Windows.cs Enables clip host and ensures content/layout are cleared and detached correctly (incl. disconnect).
src/Controls/tests/DeviceTests/Elements/Border/BorderTests.Windows.cs Adds/updates device tests validating transformed clipping and layout invalidation scenarios.

Review details

  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

@kubaflo

This comment has been minimized.

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Aug 14, 2026
Copilot AI review requested due to automatic review settings August 14, 2026 12:21
Clear stale clipping geometry for either non-positive dimension and remove the unnecessary DisconnectHandler override so the fix adds no public API surface.

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

Copilot-Session: 9ea69150-3ceb-40d9-959b-b4f509322d9b

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.

Review details

Suppressed comments (2)

src/Controls/tests/DeviceTests/Elements/Border/BorderTests.Windows.cs:314

  • ToBitmap returns a CanvasBitmap (IDisposable). In the polling loop this allocates multiple bitmaps without disposing them, which can add unnecessary memory/handle pressure and flakiness on constrained CI VMs. Dispose each iteration.
					while (renderedRedPixels == 0 && DateTime.UtcNow < timeout)
					{
						var bitmap = await handler.PlatformView.ToBitmap(MauiContext);
						renderedRedPixels = CountRedPixels(bitmap);

src/Core/src/Platform/Windows/ContentPanel.cs:16

  • using Microsoft.UI.Xaml.Controls; appears unused in this file (no types from that namespace are referenced). Keeping it may trigger IDE0005/cleanup analyzers in builds that enforce unused-using removal.
using Microsoft.UI.Xaml.Controls;
  • Files reviewed: 4/4 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@MauiBot MauiBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Expert Review — 5 findings

See inline comments for details.

MauiBot

This comment was marked as outdated.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) and removed s/agent-review-in-progress AI review is currently running for this PR labels Aug 14, 2026

@kubaflo kubaflo 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.

Could you please check the ai's suggestions?

Route cross-platform measure invalidation directly to the stationary clip host instead of invalidating it during every layout pass. Refresh cached layout when handlers reconnect and add focused caching coverage.

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

Copilot-Session: 9ea69150-3ceb-40d9-959b-b4f509322d9b
Copilot AI review requested due to automatic review settings August 14, 2026 20:29

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.

Review details

Suppressed comments (1)

src/Core/src/Platform/Windows/ContentPanel.cs:17

  • using Microsoft.UI.Xaml.Controls; appears unused in this file (no types from that namespace are referenced), which can trigger IDE0005/unnecessary-using analyzers in CI. Consider removing it.
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Automation.Peers;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Hosting;
  • Files reviewed: 5/5 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Clamp inset clip geometry when the stroke consumes the available size, preserve an empty rounded aperture, and let derived handlers observe hosted content before teardown.

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

Copilot-Session: 9ea69150-3ceb-40d9-959b-b4f509322d9b
@github-actions

Copy link
Copy Markdown
Contributor

Skill Validation Results

@jfversluis — new skill validation results are available based on this last commit: 8dfc5c4.
To request a fresh validation after new comments or commits, comment /evaluate-skills.

Overall Needs attention Static Passed LLM Needs attention Skills 24 Agents 6

⚠️ Skill Validation Results — 8dfc5c4 · [Windows] Fix Border clipping for transformed content · 2026-08-20T10:48:13Z

✅ Static Checks Passed

Skills: 24 | Eval specs linted: 16

Full lint output
── .github/skills/agentic-labeler/tests/eval.vally.yaml
npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE   package: '@microsoft/vally-cli@0.12.0',
npm warn EBADENGINE   required: { npm: '>=11.11.1', node: '>=22.0.0' },
npm warn EBADENGINE   current: { node: 'v22.23.2', npm: '10.9.8' }
npm warn EBADENGINE }
npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE   package: '@microsoft/vally@0.12.0',
npm warn EBADENGINE   required: { npm: '>=11.11.1', node: '>=22.0.0' },
npm warn EBADENGINE   current: { node: 'v22.23.2', npm: '10.9.8' }
npm warn EBADENGINE }
npm warn EBADENGINE Unsupported engine {
npm warn EBADENGINE   package: '@microsoft/vally-server@0.12.0',
npm warn EBADENGINE   required: { npm: '>=11.11.1', node: '>=22.0.0' },
npm warn EBADENGINE   current: { node: 'v22.23.2', npm: '10.9.8' }
npm warn EBADENGINE }
Vally collects pseudonymous usage telemetry (command name, version, outcome, duration, persistent device identifier (when available), and coarse OS/runtime info) to improve the product. No prompts, datasets, file paths, or arguments are collected.
Opt out any time by setting VALLY_TELEMETRY_OPTOUT=1 or DO_NOT_TRACK=1.
Learn more: https://aka.ms/vally/telemetry
✔ .github/skills/agentic-labeler/tests/eval.vally.yaml is valid
── .github/skills/analyze-sessions/tests/eval.vally.yaml
✔ .github/skills/analyze-sessions/tests/eval.vally.yaml is valid
── .github/skills/ci-fix/tests/eval.ownership.vally.yaml
✔ .github/skills/ci-fix/tests/eval.ownership.vally.yaml is valid
── .github/skills/ci-fix/tests/eval.vally.yaml
✔ .github/skills/ci-fix/tests/eval.vally.yaml is valid
── .github/skills/code-review/tests/eval.inline-findings.vally.yaml
✔ .github/skills/code-review/tests/eval.inline-findings.vally.yaml is valid
── .github/skills/code-review/tests/eval.producer-trace.vally.yaml
✔ .github/skills/code-review/tests/eval.producer-trace.vally.yaml is valid
── .github/skills/code-review/tests/eval.trim-aot.vally.yaml
✔ .github/skills/code-review/tests/eval.trim-aot.vally.yaml is valid
── .github/skills/code-review/tests/eval.vally.yaml
✔ .github/skills/code-review/tests/eval.vally.yaml is valid
── .github/skills/code-review/tests/hermeticity.vally.yaml
✔ .github/skills/code-review/tests/hermeticity.vally.yaml is valid
── .github/skills/code-review/tests/soak.capability.vally.yaml
✔ .github/skills/code-review/tests/soak.capability.vally.yaml is valid
── .github/skills/evaluate-pr-tests/tests/eval.vally.yaml
✔ .github/skills/evaluate-pr-tests/tests/eval.vally.yaml is valid
── .github/skills/pr-review/tests/eval.gh-auth.vally.yaml
✔ .github/skills/pr-review/tests/eval.gh-auth.vally.yaml is valid
── .github/skills/try-fix/tests/eval.restore.vally.yaml
✔ .github/skills/try-fix/tests/eval.restore.vally.yaml is valid
── .github/skills/try-fix/tests/eval.vally.yaml
✔ .github/skills/try-fix/tests/eval.vally.yaml is valid
── .github/skills/verify-tests-fail-without-fix/tests/eval.protocol.vally.yaml
✔ .github/skills/verify-tests-fail-without-fix/tests/eval.protocol.vally.yaml is valid
── .github/skills/verify-tests-fail-without-fix/tests/eval.vally.yaml
✔ .github/skills/verify-tests-fail-without-fix/tests/eval.vally.yaml is valid

⚠️ LLM Evaluation Incomplete

No valid JUnit suite results were found for: agentic-labeler, analyze-sessions, ci-fix, code-review, evaluate-pr-tests, pr-review, try-fix, verify-tests-fail-without-fix.

🔍 Full results and investigation steps

The pull request targets inflight/current, so merging main imported unrelated repository and workflow changes into the PR diff.

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

Copilot-Session: 9ea69150-3ceb-40d9-959b-b4f509322d9b
Preserve the stationary Windows Border clip host while integrating current layout, content reparenting, and SwipeControl base changes. Repair stale content ownership when views move between clip hosts or generic MauiPanel parents.

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

Copilot-Session: 9ea69150-3ceb-40d9-959b-b4f509322d9b
@kubaflo
kubaflo merged commit a4e7e63 into inflight/current Aug 20, 2026
29 of 36 checks passed
@kubaflo
kubaflo deleted the jfversluis-fix-border-clipping-windows branch August 20, 2026 14:58
@github-actions github-actions Bot added this to the .NET 10 SR11 milestone Aug 20, 2026
kubaflo added a commit that referenced this pull request Aug 27, 2026
<!-- 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!

Fixes #17523

## Root cause

Windows attached the Border's `CompositionGeometricClip` directly to the
content visual while authoring the geometry in the parent `ContentPanel`
coordinate space. Scale, rotation, and translation therefore transformed
the clip together with the content instead of keeping the Border
aperture stationary.

## Fix

- Place Border content inside a Border-only stationary native clip host
and attach the geometric clip to that host.
- Route cross-platform measure invalidation to both native layers while
preserving WinUI's cached subtree measure on unrelated parent layout
passes.
- Avoid re-entering measure from arrange when a layout owner changes;
the normal invalidated measure pass remains authoritative.
- Preserve the cross-platform arranged size through the native clip
host, including detached and reconnected layout-owner transitions.
- Cache stable composition and rectangular bounds clip geometry,
rebuilding only when geometry inputs change.
- Tear down layout owners, hosted content, stroke references, and cached
clip state when the handler disconnects, after derived handler
disconnect hooks have observed the intact platform view.
- Safely ignore late invalidation after handler disconnect and
synchronize direct or reconnect-driven layout-owner changes with the
clip host.
- Preserve current cross-parent content reparenting while clearing stale
clip-host ownership when content moves Border → Border, Border → generic
`MauiPanel`, or back again.
- Handle zero-by-infinite WinUI measure constraints without invoking
cross-platform layout.
- Keep layout invalidation flowing for initial asynchronous image loads
and runtime content-size, `FontSize`, and `Padding` changes without
requiring an outer window resize.
- Preserve explicit Border sizing, stroke/shadow behavior, nested layout
clipping, content replacement, custom handler activation and mapper
customization, shape removal, and accessibility behavior.
- Clamp stroke-inset geometry to nonnegative dimensions and preserve an
explicitly empty aperture when the stroke consumes all available content
space, including rounded shapes.
- Clear stale clipping geometry whenever either arranged dimension is
non-positive.
- Remove the obsolete nested `LayoutPanel` clip exception because the
XAML rectangular clip and Border composition clip now live on separate
visuals.
- Update the three affected WinUI Image AspectFill baselines for the
stationary clip host's one-pixel antialiased inner edge; image content
remains pixel-identical.

This is an implementation-only Windows fix; it adds no public APIs.

## Before / after video proof

**Before — issue author's attached reproduction, minimally retargeted to
the current Windows TFM:** transformed image content escapes the
stationary ellipse, rounded rectangle, and triangle apertures as image
scale changes.


https://github.com/user-attachments/assets/7cf6b0fc-c101-44df-ba5b-841131014708

**After — final reviewed PR gallery build using the exact
`BorderResizeContent` source scenario:** the same scale interaction
changes the image while each Border aperture remains stationary and
correctly clips its content.


https://github.com/user-attachments/assets/97a4429a-c32c-4c9f-9252-957b8f2c5e8f

Both recordings use a 1280×720 window. Pixel analysis of the recorded
scale-4 frames detected transformed image pixels outside the three
Border regions before the fix and **0 outside after the fix**.

## Validation

- Windows Border device tests: **38 passed, 0 failed, 0 skipped, 0
errors**.
- Added coverage for scale, rotation, translation, combined transforms,
shadows, nested layouts, initial asynchronous image rendering, runtime
`FontSize` and `Padding`, explicit sizing, content replacement, shape
removal, disconnect/reconnect, derived disconnect ordering, teardown
cleanup, direct layout-owner changes, derived handlers, clip ownership,
cross-host and generic-parent reparenting, composition and bounds clip
reuse, zero-by-infinite constraints, stroke-consuming zero-interior
geometry, rounded empty apertures, cross-platform arranged-size
propagation, automation, and layout-cache reuse.
- Exact final `BorderResizeContent.xaml` gallery proof ran without
resizing the window:
- Image scale 1 → 4 changed 14,673 pixels inside the Border shapes and 0
outside.
- Font size 40 → 120 changed 11,584 pixels inside the Border shapes and
0 outside.
  - All images rendered on initial load.
- The repository's production `MagickNetVisualComparer` passes all three
updated WinUI Image AspectFill snapshots at the default 0.005 RMS
threshold. The accepted delta is confined to the one-pixel Border edge
with zero changed pixels in the image interior.
- Multiple independent MAUI expert, adversarial, and layout/performance
reviews completed with no remaining actionable findings.

@jstedfast, could you please test the PR artifacts against the original
`BorderResizeContent` reproduction and confirm that initial rendering,
transformed clipping, runtime font-size changes, and resizing now behave
correctly?

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 2, 2026
<!-- 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!

Fixes #17523

## Root cause

Windows attached the Border's `CompositionGeometricClip` directly to the
content visual while authoring the geometry in the parent `ContentPanel`
coordinate space. Scale, rotation, and translation therefore transformed
the clip together with the content instead of keeping the Border
aperture stationary.

## Fix

- Place Border content inside a Border-only stationary native clip host
and attach the geometric clip to that host.
- Route cross-platform measure invalidation to both native layers while
preserving WinUI's cached subtree measure on unrelated parent layout
passes.
- Avoid re-entering measure from arrange when a layout owner changes;
the normal invalidated measure pass remains authoritative.
- Preserve the cross-platform arranged size through the native clip
host, including detached and reconnected layout-owner transitions.
- Cache stable composition and rectangular bounds clip geometry,
rebuilding only when geometry inputs change.
- Tear down layout owners, hosted content, stroke references, and cached
clip state when the handler disconnects, after derived handler
disconnect hooks have observed the intact platform view.
- Safely ignore late invalidation after handler disconnect and
synchronize direct or reconnect-driven layout-owner changes with the
clip host.
- Preserve current cross-parent content reparenting while clearing stale
clip-host ownership when content moves Border → Border, Border → generic
`MauiPanel`, or back again.
- Handle zero-by-infinite WinUI measure constraints without invoking
cross-platform layout.
- Keep layout invalidation flowing for initial asynchronous image loads
and runtime content-size, `FontSize`, and `Padding` changes without
requiring an outer window resize.
- Preserve explicit Border sizing, stroke/shadow behavior, nested layout
clipping, content replacement, custom handler activation and mapper
customization, shape removal, and accessibility behavior.
- Clamp stroke-inset geometry to nonnegative dimensions and preserve an
explicitly empty aperture when the stroke consumes all available content
space, including rounded shapes.
- Clear stale clipping geometry whenever either arranged dimension is
non-positive.
- Remove the obsolete nested `LayoutPanel` clip exception because the
XAML rectangular clip and Border composition clip now live on separate
visuals.
- Update the three affected WinUI Image AspectFill baselines for the
stationary clip host's one-pixel antialiased inner edge; image content
remains pixel-identical.

This is an implementation-only Windows fix; it adds no public APIs.

## Before / after video proof

**Before — issue author's attached reproduction, minimally retargeted to
the current Windows TFM:** transformed image content escapes the
stationary ellipse, rounded rectangle, and triangle apertures as image
scale changes.


https://github.com/user-attachments/assets/7cf6b0fc-c101-44df-ba5b-841131014708

**After — final reviewed PR gallery build using the exact
`BorderResizeContent` source scenario:** the same scale interaction
changes the image while each Border aperture remains stationary and
correctly clips its content.


https://github.com/user-attachments/assets/97a4429a-c32c-4c9f-9252-957b8f2c5e8f

Both recordings use a 1280×720 window. Pixel analysis of the recorded
scale-4 frames detected transformed image pixels outside the three
Border regions before the fix and **0 outside after the fix**.

## Validation

- Windows Border device tests: **38 passed, 0 failed, 0 skipped, 0
errors**.
- Added coverage for scale, rotation, translation, combined transforms,
shadows, nested layouts, initial asynchronous image rendering, runtime
`FontSize` and `Padding`, explicit sizing, content replacement, shape
removal, disconnect/reconnect, derived disconnect ordering, teardown
cleanup, direct layout-owner changes, derived handlers, clip ownership,
cross-host and generic-parent reparenting, composition and bounds clip
reuse, zero-by-infinite constraints, stroke-consuming zero-interior
geometry, rounded empty apertures, cross-platform arranged-size
propagation, automation, and layout-cache reuse.
- Exact final `BorderResizeContent.xaml` gallery proof ran without
resizing the window:
- Image scale 1 → 4 changed 14,673 pixels inside the Border shapes and 0
outside.
- Font size 40 → 120 changed 11,584 pixels inside the Border shapes and
0 outside.
  - All images rendered on initial load.
- The repository's production `MagickNetVisualComparer` passes all three
updated WinUI Image AspectFill snapshots at the default 0.005 RMS
threshold. The accepted delta is confined to the one-pixel Border edge
with zero changed pixels in the image interior.
- Multiple independent MAUI expert, adversarial, and layout/performance
reviews completed with no remaining actionable findings.

@jstedfast, could you please test the PR artifacts against the original
`BorderResizeContent` reproduction and confirm that initial rendering,
transformed clipping, runtime font-size changes, and resizing now behave
correctly?

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 3, 2026
<!-- 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!

Fixes #17523

## Root cause

Windows attached the Border's `CompositionGeometricClip` directly to the
content visual while authoring the geometry in the parent `ContentPanel`
coordinate space. Scale, rotation, and translation therefore transformed
the clip together with the content instead of keeping the Border
aperture stationary.

## Fix

- Place Border content inside a Border-only stationary native clip host
and attach the geometric clip to that host.
- Route cross-platform measure invalidation to both native layers while
preserving WinUI's cached subtree measure on unrelated parent layout
passes.
- Avoid re-entering measure from arrange when a layout owner changes;
the normal invalidated measure pass remains authoritative.
- Preserve the cross-platform arranged size through the native clip
host, including detached and reconnected layout-owner transitions.
- Cache stable composition and rectangular bounds clip geometry,
rebuilding only when geometry inputs change.
- Tear down layout owners, hosted content, stroke references, and cached
clip state when the handler disconnects, after derived handler
disconnect hooks have observed the intact platform view.
- Safely ignore late invalidation after handler disconnect and
synchronize direct or reconnect-driven layout-owner changes with the
clip host.
- Preserve current cross-parent content reparenting while clearing stale
clip-host ownership when content moves Border → Border, Border → generic
`MauiPanel`, or back again.
- Handle zero-by-infinite WinUI measure constraints without invoking
cross-platform layout.
- Keep layout invalidation flowing for initial asynchronous image loads
and runtime content-size, `FontSize`, and `Padding` changes without
requiring an outer window resize.
- Preserve explicit Border sizing, stroke/shadow behavior, nested layout
clipping, content replacement, custom handler activation and mapper
customization, shape removal, and accessibility behavior.
- Clamp stroke-inset geometry to nonnegative dimensions and preserve an
explicitly empty aperture when the stroke consumes all available content
space, including rounded shapes.
- Clear stale clipping geometry whenever either arranged dimension is
non-positive.
- Remove the obsolete nested `LayoutPanel` clip exception because the
XAML rectangular clip and Border composition clip now live on separate
visuals.
- Update the three affected WinUI Image AspectFill baselines for the
stationary clip host's one-pixel antialiased inner edge; image content
remains pixel-identical.

This is an implementation-only Windows fix; it adds no public APIs.

## Before / after video proof

**Before — issue author's attached reproduction, minimally retargeted to
the current Windows TFM:** transformed image content escapes the
stationary ellipse, rounded rectangle, and triangle apertures as image
scale changes.


https://github.com/user-attachments/assets/7cf6b0fc-c101-44df-ba5b-841131014708

**After — final reviewed PR gallery build using the exact
`BorderResizeContent` source scenario:** the same scale interaction
changes the image while each Border aperture remains stationary and
correctly clips its content.


https://github.com/user-attachments/assets/97a4429a-c32c-4c9f-9252-957b8f2c5e8f

Both recordings use a 1280×720 window. Pixel analysis of the recorded
scale-4 frames detected transformed image pixels outside the three
Border regions before the fix and **0 outside after the fix**.

## Validation

- Windows Border device tests: **38 passed, 0 failed, 0 skipped, 0
errors**.
- Added coverage for scale, rotation, translation, combined transforms,
shadows, nested layouts, initial asynchronous image rendering, runtime
`FontSize` and `Padding`, explicit sizing, content replacement, shape
removal, disconnect/reconnect, derived disconnect ordering, teardown
cleanup, direct layout-owner changes, derived handlers, clip ownership,
cross-host and generic-parent reparenting, composition and bounds clip
reuse, zero-by-infinite constraints, stroke-consuming zero-interior
geometry, rounded empty apertures, cross-platform arranged-size
propagation, automation, and layout-cache reuse.
- Exact final `BorderResizeContent.xaml` gallery proof ran without
resizing the window:
- Image scale 1 → 4 changed 14,673 pixels inside the Border shapes and 0
outside.
- Font size 40 → 120 changed 11,584 pixels inside the Border shapes and
0 outside.
  - All images rendered on initial load.
- The repository's production `MagickNetVisualComparer` passes all three
updated WinUI Image AspectFill snapshots at the default 0.005 RMS
threshold. The accepted delta is confined to the one-pixel Border edge
with zero changed pixels in the image interior.
- Multiple independent MAUI expert, adversarial, and layout/performance
reviews completed with no remaining actionable findings.

@jstedfast, could you please test the PR artifacts against the original
`BorderResizeContent` reproduction and confirm that initial rendering,
transformed clipping, runtime font-size changes, and resizing now behave
correctly?

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 6, 2026
<!-- 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!

Fixes #17523

## Root cause

Windows attached the Border's `CompositionGeometricClip` directly to the
content visual while authoring the geometry in the parent `ContentPanel`
coordinate space. Scale, rotation, and translation therefore transformed
the clip together with the content instead of keeping the Border
aperture stationary.

## Fix

- Place Border content inside a Border-only stationary native clip host
and attach the geometric clip to that host.
- Route cross-platform measure invalidation to both native layers while
preserving WinUI's cached subtree measure on unrelated parent layout
passes.
- Avoid re-entering measure from arrange when a layout owner changes;
the normal invalidated measure pass remains authoritative.
- Preserve the cross-platform arranged size through the native clip
host, including detached and reconnected layout-owner transitions.
- Cache stable composition and rectangular bounds clip geometry,
rebuilding only when geometry inputs change.
- Tear down layout owners, hosted content, stroke references, and cached
clip state when the handler disconnects, after derived handler
disconnect hooks have observed the intact platform view.
- Safely ignore late invalidation after handler disconnect and
synchronize direct or reconnect-driven layout-owner changes with the
clip host.
- Preserve current cross-parent content reparenting while clearing stale
clip-host ownership when content moves Border → Border, Border → generic
`MauiPanel`, or back again.
- Handle zero-by-infinite WinUI measure constraints without invoking
cross-platform layout.
- Keep layout invalidation flowing for initial asynchronous image loads
and runtime content-size, `FontSize`, and `Padding` changes without
requiring an outer window resize.
- Preserve explicit Border sizing, stroke/shadow behavior, nested layout
clipping, content replacement, custom handler activation and mapper
customization, shape removal, and accessibility behavior.
- Clamp stroke-inset geometry to nonnegative dimensions and preserve an
explicitly empty aperture when the stroke consumes all available content
space, including rounded shapes.
- Clear stale clipping geometry whenever either arranged dimension is
non-positive.
- Remove the obsolete nested `LayoutPanel` clip exception because the
XAML rectangular clip and Border composition clip now live on separate
visuals.
- Update the three affected WinUI Image AspectFill baselines for the
stationary clip host's one-pixel antialiased inner edge; image content
remains pixel-identical.

This is an implementation-only Windows fix; it adds no public APIs.

## Before / after video proof

**Before — issue author's attached reproduction, minimally retargeted to
the current Windows TFM:** transformed image content escapes the
stationary ellipse, rounded rectangle, and triangle apertures as image
scale changes.


https://github.com/user-attachments/assets/7cf6b0fc-c101-44df-ba5b-841131014708

**After — final reviewed PR gallery build using the exact
`BorderResizeContent` source scenario:** the same scale interaction
changes the image while each Border aperture remains stationary and
correctly clips its content.


https://github.com/user-attachments/assets/97a4429a-c32c-4c9f-9252-957b8f2c5e8f

Both recordings use a 1280×720 window. Pixel analysis of the recorded
scale-4 frames detected transformed image pixels outside the three
Border regions before the fix and **0 outside after the fix**.

## Validation

- Windows Border device tests: **38 passed, 0 failed, 0 skipped, 0
errors**.
- Added coverage for scale, rotation, translation, combined transforms,
shadows, nested layouts, initial asynchronous image rendering, runtime
`FontSize` and `Padding`, explicit sizing, content replacement, shape
removal, disconnect/reconnect, derived disconnect ordering, teardown
cleanup, direct layout-owner changes, derived handlers, clip ownership,
cross-host and generic-parent reparenting, composition and bounds clip
reuse, zero-by-infinite constraints, stroke-consuming zero-interior
geometry, rounded empty apertures, cross-platform arranged-size
propagation, automation, and layout-cache reuse.
- Exact final `BorderResizeContent.xaml` gallery proof ran without
resizing the window:
- Image scale 1 → 4 changed 14,673 pixels inside the Border shapes and 0
outside.
- Font size 40 → 120 changed 11,584 pixels inside the Border shapes and
0 outside.
  - All images rendered on initial load.
- The repository's production `MagickNetVisualComparer` passes all three
updated WinUI Image AspectFill snapshots at the default 0.005 RMS
threshold. The accepted delta is confined to the one-pixel Border edge
with zero changed pixels in the image interior.
- Multiple independent MAUI expert, adversarial, and layout/performance
reviews completed with no remaining actionable findings.

@jstedfast, could you please test the PR artifacts against the original
`BorderResizeContent` reproduction and confirm that initial rendering,
transformed clipping, runtime font-size changes, and resizing now behave
correctly?

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 7, 2026
<!-- 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!

Fixes #17523

## Root cause

Windows attached the Border's `CompositionGeometricClip` directly to the
content visual while authoring the geometry in the parent `ContentPanel`
coordinate space. Scale, rotation, and translation therefore transformed
the clip together with the content instead of keeping the Border
aperture stationary.

## Fix

- Place Border content inside a Border-only stationary native clip host
and attach the geometric clip to that host.
- Route cross-platform measure invalidation to both native layers while
preserving WinUI's cached subtree measure on unrelated parent layout
passes.
- Avoid re-entering measure from arrange when a layout owner changes;
the normal invalidated measure pass remains authoritative.
- Preserve the cross-platform arranged size through the native clip
host, including detached and reconnected layout-owner transitions.
- Cache stable composition and rectangular bounds clip geometry,
rebuilding only when geometry inputs change.
- Tear down layout owners, hosted content, stroke references, and cached
clip state when the handler disconnects, after derived handler
disconnect hooks have observed the intact platform view.
- Safely ignore late invalidation after handler disconnect and
synchronize direct or reconnect-driven layout-owner changes with the
clip host.
- Preserve current cross-parent content reparenting while clearing stale
clip-host ownership when content moves Border → Border, Border → generic
`MauiPanel`, or back again.
- Handle zero-by-infinite WinUI measure constraints without invoking
cross-platform layout.
- Keep layout invalidation flowing for initial asynchronous image loads
and runtime content-size, `FontSize`, and `Padding` changes without
requiring an outer window resize.
- Preserve explicit Border sizing, stroke/shadow behavior, nested layout
clipping, content replacement, custom handler activation and mapper
customization, shape removal, and accessibility behavior.
- Clamp stroke-inset geometry to nonnegative dimensions and preserve an
explicitly empty aperture when the stroke consumes all available content
space, including rounded shapes.
- Clear stale clipping geometry whenever either arranged dimension is
non-positive.
- Remove the obsolete nested `LayoutPanel` clip exception because the
XAML rectangular clip and Border composition clip now live on separate
visuals.
- Update the three affected WinUI Image AspectFill baselines for the
stationary clip host's one-pixel antialiased inner edge; image content
remains pixel-identical.

This is an implementation-only Windows fix; it adds no public APIs.

## Before / after video proof

**Before — issue author's attached reproduction, minimally retargeted to
the current Windows TFM:** transformed image content escapes the
stationary ellipse, rounded rectangle, and triangle apertures as image
scale changes.


https://github.com/user-attachments/assets/7cf6b0fc-c101-44df-ba5b-841131014708

**After — final reviewed PR gallery build using the exact
`BorderResizeContent` source scenario:** the same scale interaction
changes the image while each Border aperture remains stationary and
correctly clips its content.


https://github.com/user-attachments/assets/97a4429a-c32c-4c9f-9252-957b8f2c5e8f

Both recordings use a 1280×720 window. Pixel analysis of the recorded
scale-4 frames detected transformed image pixels outside the three
Border regions before the fix and **0 outside after the fix**.

## Validation

- Windows Border device tests: **38 passed, 0 failed, 0 skipped, 0
errors**.
- Added coverage for scale, rotation, translation, combined transforms,
shadows, nested layouts, initial asynchronous image rendering, runtime
`FontSize` and `Padding`, explicit sizing, content replacement, shape
removal, disconnect/reconnect, derived disconnect ordering, teardown
cleanup, direct layout-owner changes, derived handlers, clip ownership,
cross-host and generic-parent reparenting, composition and bounds clip
reuse, zero-by-infinite constraints, stroke-consuming zero-interior
geometry, rounded empty apertures, cross-platform arranged-size
propagation, automation, and layout-cache reuse.
- Exact final `BorderResizeContent.xaml` gallery proof ran without
resizing the window:
- Image scale 1 → 4 changed 14,673 pixels inside the Border shapes and 0
outside.
- Font size 40 → 120 changed 11,584 pixels inside the Border shapes and
0 outside.
  - All images rendered on initial load.
- The repository's production `MagickNetVisualComparer` passes all three
updated WinUI Image AspectFill snapshots at the default 0.005 RMS
threshold. The accepted delta is confined to the one-pixel Border edge
with zero changed pixels in the image interior.
- Multiple independent MAUI expert, adversarial, and layout/performance
reviews completed with no remaining actionable findings.

@jstedfast, could you please test the PR artifacts against the original
`BorderResizeContent` reproduction and confirm that initial rendering,
transformed clipping, runtime font-size changes, and resizing now behave
correctly?

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 8, 2026
<!-- 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!

Fixes #17523

Windows attached the Border's `CompositionGeometricClip` directly to the
content visual while authoring the geometry in the parent `ContentPanel`
coordinate space. Scale, rotation, and translation therefore transformed
the clip together with the content instead of keeping the Border
aperture stationary.

- Place Border content inside a Border-only stationary native clip host
and attach the geometric clip to that host.
- Route cross-platform measure invalidation to both native layers while
preserving WinUI's cached subtree measure on unrelated parent layout
passes.
- Avoid re-entering measure from arrange when a layout owner changes;
the normal invalidated measure pass remains authoritative.
- Preserve the cross-platform arranged size through the native clip
host, including detached and reconnected layout-owner transitions.
- Cache stable composition and rectangular bounds clip geometry,
rebuilding only when geometry inputs change.
- Tear down layout owners, hosted content, stroke references, and cached
clip state when the handler disconnects, after derived handler
disconnect hooks have observed the intact platform view.
- Safely ignore late invalidation after handler disconnect and
synchronize direct or reconnect-driven layout-owner changes with the
clip host.
- Preserve current cross-parent content reparenting while clearing stale
clip-host ownership when content moves Border → Border, Border → generic
`MauiPanel`, or back again.
- Handle zero-by-infinite WinUI measure constraints without invoking
cross-platform layout.
- Keep layout invalidation flowing for initial asynchronous image loads
and runtime content-size, `FontSize`, and `Padding` changes without
requiring an outer window resize.
- Preserve explicit Border sizing, stroke/shadow behavior, nested layout
clipping, content replacement, custom handler activation and mapper
customization, shape removal, and accessibility behavior.
- Clamp stroke-inset geometry to nonnegative dimensions and preserve an
explicitly empty aperture when the stroke consumes all available content
space, including rounded shapes.
- Clear stale clipping geometry whenever either arranged dimension is
non-positive.
- Remove the obsolete nested `LayoutPanel` clip exception because the
XAML rectangular clip and Border composition clip now live on separate
visuals.
- Update the three affected WinUI Image AspectFill baselines for the
stationary clip host's one-pixel antialiased inner edge; image content
remains pixel-identical.

This is an implementation-only Windows fix; it adds no public APIs.

**Before — issue author's attached reproduction, minimally retargeted to
the current Windows TFM:** transformed image content escapes the
stationary ellipse, rounded rectangle, and triangle apertures as image
scale changes.

https://github.com/user-attachments/assets/7cf6b0fc-c101-44df-ba5b-841131014708

**After — final reviewed PR gallery build using the exact
`BorderResizeContent` source scenario:** the same scale interaction
changes the image while each Border aperture remains stationary and
correctly clips its content.

https://github.com/user-attachments/assets/97a4429a-c32c-4c9f-9252-957b8f2c5e8f

Both recordings use a 1280×720 window. Pixel analysis of the recorded
scale-4 frames detected transformed image pixels outside the three
Border regions before the fix and **0 outside after the fix**.

- Windows Border device tests: **38 passed, 0 failed, 0 skipped, 0
errors**.
- Added coverage for scale, rotation, translation, combined transforms,
shadows, nested layouts, initial asynchronous image rendering, runtime
`FontSize` and `Padding`, explicit sizing, content replacement, shape
removal, disconnect/reconnect, derived disconnect ordering, teardown
cleanup, direct layout-owner changes, derived handlers, clip ownership,
cross-host and generic-parent reparenting, composition and bounds clip
reuse, zero-by-infinite constraints, stroke-consuming zero-interior
geometry, rounded empty apertures, cross-platform arranged-size
propagation, automation, and layout-cache reuse.
- Exact final `BorderResizeContent.xaml` gallery proof ran without
resizing the window:
- Image scale 1 → 4 changed 14,673 pixels inside the Border shapes and 0
outside.
- Font size 40 → 120 changed 11,584 pixels inside the Border shapes and
0 outside.
  - All images rendered on initial load.
- The repository's production `MagickNetVisualComparer` passes all three
updated WinUI Image AspectFill snapshots at the default 0.005 RMS
threshold. The accepted delta is confined to the one-pixel Border edge
with zero changed pixels in the image interior.
- Multiple independent MAUI expert, adversarial, and layout/performance
reviews completed with no remaining actionable findings.

@jstedfast, could you please test the PR artifacts against the original
`BorderResizeContent` reproduction and confirm that initial rendering,
transformed clipping, runtime font-size changes, and resizing now behave
correctly?

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 9, 2026
<!-- 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!

Fixes #17523

Windows attached the Border's `CompositionGeometricClip` directly to the
content visual while authoring the geometry in the parent `ContentPanel`
coordinate space. Scale, rotation, and translation therefore transformed
the clip together with the content instead of keeping the Border
aperture stationary.

- Place Border content inside a Border-only stationary native clip host
and attach the geometric clip to that host.
- Route cross-platform measure invalidation to both native layers while
preserving WinUI's cached subtree measure on unrelated parent layout
passes.
- Avoid re-entering measure from arrange when a layout owner changes;
the normal invalidated measure pass remains authoritative.
- Preserve the cross-platform arranged size through the native clip
host, including detached and reconnected layout-owner transitions.
- Cache stable composition and rectangular bounds clip geometry,
rebuilding only when geometry inputs change.
- Tear down layout owners, hosted content, stroke references, and cached
clip state when the handler disconnects, after derived handler
disconnect hooks have observed the intact platform view.
- Safely ignore late invalidation after handler disconnect and
synchronize direct or reconnect-driven layout-owner changes with the
clip host.
- Preserve current cross-parent content reparenting while clearing stale
clip-host ownership when content moves Border → Border, Border → generic
`MauiPanel`, or back again.
- Handle zero-by-infinite WinUI measure constraints without invoking
cross-platform layout.
- Keep layout invalidation flowing for initial asynchronous image loads
and runtime content-size, `FontSize`, and `Padding` changes without
requiring an outer window resize.
- Preserve explicit Border sizing, stroke/shadow behavior, nested layout
clipping, content replacement, custom handler activation and mapper
customization, shape removal, and accessibility behavior.
- Clamp stroke-inset geometry to nonnegative dimensions and preserve an
explicitly empty aperture when the stroke consumes all available content
space, including rounded shapes.
- Clear stale clipping geometry whenever either arranged dimension is
non-positive.
- Remove the obsolete nested `LayoutPanel` clip exception because the
XAML rectangular clip and Border composition clip now live on separate
visuals.
- Update the three affected WinUI Image AspectFill baselines for the
stationary clip host's one-pixel antialiased inner edge; image content
remains pixel-identical.

This is an implementation-only Windows fix; it adds no public APIs.

**Before — issue author's attached reproduction, minimally retargeted to
the current Windows TFM:** transformed image content escapes the
stationary ellipse, rounded rectangle, and triangle apertures as image
scale changes.

https://github.com/user-attachments/assets/7cf6b0fc-c101-44df-ba5b-841131014708

**After — final reviewed PR gallery build using the exact
`BorderResizeContent` source scenario:** the same scale interaction
changes the image while each Border aperture remains stationary and
correctly clips its content.

https://github.com/user-attachments/assets/97a4429a-c32c-4c9f-9252-957b8f2c5e8f

Both recordings use a 1280×720 window. Pixel analysis of the recorded
scale-4 frames detected transformed image pixels outside the three
Border regions before the fix and **0 outside after the fix**.

- Windows Border device tests: **38 passed, 0 failed, 0 skipped, 0
errors**.
- Added coverage for scale, rotation, translation, combined transforms,
shadows, nested layouts, initial asynchronous image rendering, runtime
`FontSize` and `Padding`, explicit sizing, content replacement, shape
removal, disconnect/reconnect, derived disconnect ordering, teardown
cleanup, direct layout-owner changes, derived handlers, clip ownership,
cross-host and generic-parent reparenting, composition and bounds clip
reuse, zero-by-infinite constraints, stroke-consuming zero-interior
geometry, rounded empty apertures, cross-platform arranged-size
propagation, automation, and layout-cache reuse.
- Exact final `BorderResizeContent.xaml` gallery proof ran without
resizing the window:
- Image scale 1 → 4 changed 14,673 pixels inside the Border shapes and 0
outside.
- Font size 40 → 120 changed 11,584 pixels inside the Border shapes and
0 outside.
  - All images rendered on initial load.
- The repository's production `MagickNetVisualComparer` passes all three
updated WinUI Image AspectFill snapshots at the default 0.005 RMS
threshold. The accepted delta is confined to the one-pixel Border edge
with zero changed pixels in the image interior.
- Multiple independent MAUI expert, adversarial, and layout/performance
reviews completed with no remaining actionable findings.

@jstedfast, could you please test the PR artifacts against the original
`BorderResizeContent` reproduction and confirm that initial rendering,
transformed clipping, runtime font-size changes, and resizing now behave
correctly?

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 11, 2026
<!-- 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!

Fixes #17523

Windows attached the Border's `CompositionGeometricClip` directly to the
content visual while authoring the geometry in the parent `ContentPanel`
coordinate space. Scale, rotation, and translation therefore transformed
the clip together with the content instead of keeping the Border
aperture stationary.

- Place Border content inside a Border-only stationary native clip host
and attach the geometric clip to that host.
- Route cross-platform measure invalidation to both native layers while
preserving WinUI's cached subtree measure on unrelated parent layout
passes.
- Avoid re-entering measure from arrange when a layout owner changes;
the normal invalidated measure pass remains authoritative.
- Preserve the cross-platform arranged size through the native clip
host, including detached and reconnected layout-owner transitions.
- Cache stable composition and rectangular bounds clip geometry,
rebuilding only when geometry inputs change.
- Tear down layout owners, hosted content, stroke references, and cached
clip state when the handler disconnects, after derived handler
disconnect hooks have observed the intact platform view.
- Safely ignore late invalidation after handler disconnect and
synchronize direct or reconnect-driven layout-owner changes with the
clip host.
- Preserve current cross-parent content reparenting while clearing stale
clip-host ownership when content moves Border → Border, Border → generic
`MauiPanel`, or back again.
- Handle zero-by-infinite WinUI measure constraints without invoking
cross-platform layout.
- Keep layout invalidation flowing for initial asynchronous image loads
and runtime content-size, `FontSize`, and `Padding` changes without
requiring an outer window resize.
- Preserve explicit Border sizing, stroke/shadow behavior, nested layout
clipping, content replacement, custom handler activation and mapper
customization, shape removal, and accessibility behavior.
- Clamp stroke-inset geometry to nonnegative dimensions and preserve an
explicitly empty aperture when the stroke consumes all available content
space, including rounded shapes.
- Clear stale clipping geometry whenever either arranged dimension is
non-positive.
- Remove the obsolete nested `LayoutPanel` clip exception because the
XAML rectangular clip and Border composition clip now live on separate
visuals.
- Update the three affected WinUI Image AspectFill baselines for the
stationary clip host's one-pixel antialiased inner edge; image content
remains pixel-identical.

This is an implementation-only Windows fix; it adds no public APIs.

**Before — issue author's attached reproduction, minimally retargeted to
the current Windows TFM:** transformed image content escapes the
stationary ellipse, rounded rectangle, and triangle apertures as image
scale changes.

https://github.com/user-attachments/assets/7cf6b0fc-c101-44df-ba5b-841131014708

**After — final reviewed PR gallery build using the exact
`BorderResizeContent` source scenario:** the same scale interaction
changes the image while each Border aperture remains stationary and
correctly clips its content.

https://github.com/user-attachments/assets/97a4429a-c32c-4c9f-9252-957b8f2c5e8f

Both recordings use a 1280×720 window. Pixel analysis of the recorded
scale-4 frames detected transformed image pixels outside the three
Border regions before the fix and **0 outside after the fix**.

- Windows Border device tests: **38 passed, 0 failed, 0 skipped, 0
errors**.
- Added coverage for scale, rotation, translation, combined transforms,
shadows, nested layouts, initial asynchronous image rendering, runtime
`FontSize` and `Padding`, explicit sizing, content replacement, shape
removal, disconnect/reconnect, derived disconnect ordering, teardown
cleanup, direct layout-owner changes, derived handlers, clip ownership,
cross-host and generic-parent reparenting, composition and bounds clip
reuse, zero-by-infinite constraints, stroke-consuming zero-interior
geometry, rounded empty apertures, cross-platform arranged-size
propagation, automation, and layout-cache reuse.
- Exact final `BorderResizeContent.xaml` gallery proof ran without
resizing the window:
- Image scale 1 → 4 changed 14,673 pixels inside the Border shapes and 0
outside.
- Font size 40 → 120 changed 11,584 pixels inside the Border shapes and
0 outside.
  - All images rendered on initial load.
- The repository's production `MagickNetVisualComparer` passes all three
updated WinUI Image AspectFill snapshots at the default 0.005 RMS
threshold. The accepted delta is confined to the one-pixel Border edge
with zero changed pixels in the image interior.
- Multiple independent MAUI expert, adversarial, and layout/performance
reviews completed with no remaining actionable findings.

@jstedfast, could you please test the PR artifacts against the original
`BorderResizeContent` reproduction and confirm that initial rendering,
transformed clipping, runtime font-size changes, and resizing now behave
correctly?

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 15, 2026
<!-- 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!

Fixes #17523

Windows attached the Border's `CompositionGeometricClip` directly to the
content visual while authoring the geometry in the parent `ContentPanel`
coordinate space. Scale, rotation, and translation therefore transformed
the clip together with the content instead of keeping the Border
aperture stationary.

- Place Border content inside a Border-only stationary native clip host
and attach the geometric clip to that host.
- Route cross-platform measure invalidation to both native layers while
preserving WinUI's cached subtree measure on unrelated parent layout
passes.
- Avoid re-entering measure from arrange when a layout owner changes;
the normal invalidated measure pass remains authoritative.
- Preserve the cross-platform arranged size through the native clip
host, including detached and reconnected layout-owner transitions.
- Cache stable composition and rectangular bounds clip geometry,
rebuilding only when geometry inputs change.
- Tear down layout owners, hosted content, stroke references, and cached
clip state when the handler disconnects, after derived handler
disconnect hooks have observed the intact platform view.
- Safely ignore late invalidation after handler disconnect and
synchronize direct or reconnect-driven layout-owner changes with the
clip host.
- Preserve current cross-parent content reparenting while clearing stale
clip-host ownership when content moves Border → Border, Border → generic
`MauiPanel`, or back again.
- Handle zero-by-infinite WinUI measure constraints without invoking
cross-platform layout.
- Keep layout invalidation flowing for initial asynchronous image loads
and runtime content-size, `FontSize`, and `Padding` changes without
requiring an outer window resize.
- Preserve explicit Border sizing, stroke/shadow behavior, nested layout
clipping, content replacement, custom handler activation and mapper
customization, shape removal, and accessibility behavior.
- Clamp stroke-inset geometry to nonnegative dimensions and preserve an
explicitly empty aperture when the stroke consumes all available content
space, including rounded shapes.
- Clear stale clipping geometry whenever either arranged dimension is
non-positive.
- Remove the obsolete nested `LayoutPanel` clip exception because the
XAML rectangular clip and Border composition clip now live on separate
visuals.
- Update the three affected WinUI Image AspectFill baselines for the
stationary clip host's one-pixel antialiased inner edge; image content
remains pixel-identical.

This is an implementation-only Windows fix; it adds no public APIs.

**Before — issue author's attached reproduction, minimally retargeted to
the current Windows TFM:** transformed image content escapes the
stationary ellipse, rounded rectangle, and triangle apertures as image
scale changes.

https://github.com/user-attachments/assets/7cf6b0fc-c101-44df-ba5b-841131014708

**After — final reviewed PR gallery build using the exact
`BorderResizeContent` source scenario:** the same scale interaction
changes the image while each Border aperture remains stationary and
correctly clips its content.

https://github.com/user-attachments/assets/97a4429a-c32c-4c9f-9252-957b8f2c5e8f

Both recordings use a 1280×720 window. Pixel analysis of the recorded
scale-4 frames detected transformed image pixels outside the three
Border regions before the fix and **0 outside after the fix**.

- Windows Border device tests: **38 passed, 0 failed, 0 skipped, 0
errors**.
- Added coverage for scale, rotation, translation, combined transforms,
shadows, nested layouts, initial asynchronous image rendering, runtime
`FontSize` and `Padding`, explicit sizing, content replacement, shape
removal, disconnect/reconnect, derived disconnect ordering, teardown
cleanup, direct layout-owner changes, derived handlers, clip ownership,
cross-host and generic-parent reparenting, composition and bounds clip
reuse, zero-by-infinite constraints, stroke-consuming zero-interior
geometry, rounded empty apertures, cross-platform arranged-size
propagation, automation, and layout-cache reuse.
- Exact final `BorderResizeContent.xaml` gallery proof ran without
resizing the window:
- Image scale 1 → 4 changed 14,673 pixels inside the Border shapes and 0
outside.
- Font size 40 → 120 changed 11,584 pixels inside the Border shapes and
0 outside.
  - All images rendered on initial load.
- The repository's production `MagickNetVisualComparer` passes all three
updated WinUI Image AspectFill snapshots at the default 0.005 RMS
threshold. The accepted delta is confined to the one-pixel Border edge
with zero changed pixels in the image interior.
- Multiple independent MAUI expert, adversarial, and layout/performance
reviews completed with no remaining actionable findings.

@jstedfast, could you please test the PR artifacts against the original
`BorderResizeContent` reproduction and confirm that initial rendering,
transformed clipping, runtime font-size changes, and resizing now behave
correctly?

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
kubaflo added a commit that referenced this pull request Sep 18, 2026
<!-- 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!

Fixes #17523

Windows attached the Border's `CompositionGeometricClip` directly to the
content visual while authoring the geometry in the parent `ContentPanel`
coordinate space. Scale, rotation, and translation therefore transformed
the clip together with the content instead of keeping the Border
aperture stationary.

- Place Border content inside a Border-only stationary native clip host
and attach the geometric clip to that host.
- Route cross-platform measure invalidation to both native layers while
preserving WinUI's cached subtree measure on unrelated parent layout
passes.
- Avoid re-entering measure from arrange when a layout owner changes;
the normal invalidated measure pass remains authoritative.
- Preserve the cross-platform arranged size through the native clip
host, including detached and reconnected layout-owner transitions.
- Cache stable composition and rectangular bounds clip geometry,
rebuilding only when geometry inputs change.
- Tear down layout owners, hosted content, stroke references, and cached
clip state when the handler disconnects, after derived handler
disconnect hooks have observed the intact platform view.
- Safely ignore late invalidation after handler disconnect and
synchronize direct or reconnect-driven layout-owner changes with the
clip host.
- Preserve current cross-parent content reparenting while clearing stale
clip-host ownership when content moves Border → Border, Border → generic
`MauiPanel`, or back again.
- Handle zero-by-infinite WinUI measure constraints without invoking
cross-platform layout.
- Keep layout invalidation flowing for initial asynchronous image loads
and runtime content-size, `FontSize`, and `Padding` changes without
requiring an outer window resize.
- Preserve explicit Border sizing, stroke/shadow behavior, nested layout
clipping, content replacement, custom handler activation and mapper
customization, shape removal, and accessibility behavior.
- Clamp stroke-inset geometry to nonnegative dimensions and preserve an
explicitly empty aperture when the stroke consumes all available content
space, including rounded shapes.
- Clear stale clipping geometry whenever either arranged dimension is
non-positive.
- Remove the obsolete nested `LayoutPanel` clip exception because the
XAML rectangular clip and Border composition clip now live on separate
visuals.
- Update the three affected WinUI Image AspectFill baselines for the
stationary clip host's one-pixel antialiased inner edge; image content
remains pixel-identical.

This is an implementation-only Windows fix; it adds no public APIs.

**Before — issue author's attached reproduction, minimally retargeted to
the current Windows TFM:** transformed image content escapes the
stationary ellipse, rounded rectangle, and triangle apertures as image
scale changes.

https://github.com/user-attachments/assets/7cf6b0fc-c101-44df-ba5b-841131014708

**After — final reviewed PR gallery build using the exact
`BorderResizeContent` source scenario:** the same scale interaction
changes the image while each Border aperture remains stationary and
correctly clips its content.

https://github.com/user-attachments/assets/97a4429a-c32c-4c9f-9252-957b8f2c5e8f

Both recordings use a 1280×720 window. Pixel analysis of the recorded
scale-4 frames detected transformed image pixels outside the three
Border regions before the fix and **0 outside after the fix**.

- Windows Border device tests: **38 passed, 0 failed, 0 skipped, 0
errors**.
- Added coverage for scale, rotation, translation, combined transforms,
shadows, nested layouts, initial asynchronous image rendering, runtime
`FontSize` and `Padding`, explicit sizing, content replacement, shape
removal, disconnect/reconnect, derived disconnect ordering, teardown
cleanup, direct layout-owner changes, derived handlers, clip ownership,
cross-host and generic-parent reparenting, composition and bounds clip
reuse, zero-by-infinite constraints, stroke-consuming zero-interior
geometry, rounded empty apertures, cross-platform arranged-size
propagation, automation, and layout-cache reuse.
- Exact final `BorderResizeContent.xaml` gallery proof ran without
resizing the window:
- Image scale 1 → 4 changed 14,673 pixels inside the Border shapes and 0
outside.
- Font size 40 → 120 changed 11,584 pixels inside the Border shapes and
0 outside.
  - All images rendered on initial load.
- The repository's production `MagickNetVisualComparer` passes all three
updated WinUI Image AspectFill snapshots at the default 0.005 RMS
threshold. The accepted delta is confined to the one-pixel Border edge
with zero changed pixels in the image interior.
- Multiple independent MAUI expert, adversarial, and layout/performance
reviews completed with no remaining actionable findings.

@jstedfast, could you please test the PR artifacts against the original
`BorderResizeContent` reproduction and confirm that initial rendering,
transformed clipping, runtime font-size changes, and resizing now behave
correctly?

Co-authored-by: Jakub Florkowski <42434498+kubaflo@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 20, 2026
@github-actions github-actions Bot removed this from the .NET 10 SR11 milestone Oct 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

s/agent-approved AI agent recommends approval - PR fix is correct and optimal s/agent-fix-pr-picked AI could not beat the PR fix - PR is the best among all candidates s/agent-gate-passed AI verified tests catch the bug (fail without fix, pass with fix) s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] Border clipping incorrect when Content is scaled (or has any other Transform applied?)

8 participants