Skip to content

Fix irregular placement of views with margins - #37080

Merged
kubaflo merged 2 commits into
dotnet:inflight/currentfrom
SyedAbdulAzeemSF4852:fix-8324
Sep 2, 2026
Merged

kubaflo merged 2 commits into
dotnet:inflight/currentfrom
SyedAbdulAzeemSF4852:fix-8324

Conversation

@SyedAbdulAzeemSF4852

Copy link
Copy Markdown
Contributor

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!

Issue Details

  • When a view’s margin makes its desired size larger than its parent’s available bounds, Center and End alignment apply a negative offset that moves the view backward past the Start position, causing irregular or visually reversed placement.

Root Cause

  • DesiredSize includes the view’s margins. When those margins make the desired size larger than the available bounds, boundsWidth - desiredWidth or bounds.Height - desiredHeight becomes negative. Center and End alignment then use that negative value as an offset, moving the view backward past its Start position and visually reversing the layout.

Description of Change

  • Clamp the available alignment space to a minimum of zero in AlignHorizontal and AlignVertical. When a view’s desired size exceeds its bounds, Center and End no longer apply a negative offset and instead retain the margin-adjusted Start position.
  • Reference => Layout.cs

Issues Fixed

Fixes #8324

Validated the behaviour in the following platforms

  • Windows
  • Android
  • iOS
  • Mac

Output

Platform Before After
iOS
Mac
Windows
Android

@github-actions

github-actions Bot commented Aug 4, 2026

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 -- 37080

Or

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

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

@dotnet-policy-service dotnet-policy-service Bot added the community ✨ Community Contribution label Aug 4, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Hey there @@SyedAbdulAzeemSF4852! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

@dotnet-policy-service dotnet-policy-service Bot added the partner/syncfusion Issues / PR's with Syncfusion collaboration label Aug 4, 2026
@github-actions github-actions Bot added area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter platform/android platform/ios platform/macos macOS / Mac Catalyst platform/windows labels Aug 4, 2026
@SyedAbdulAzeemSF4852 SyedAbdulAzeemSF4852 changed the title [WIP] Fix irregular placement of views with margins Fix irregular placement of views with margins Aug 5, 2026
@sheiksyedm
sheiksyedm marked this pull request as ready for review August 5, 2026 06:22
Copilot AI lite review requested due to automatic review settings August 5, 2026 06:22
@sheiksyedm

Copy link
Copy Markdown
Contributor

/azp run maui-pr-uitests , maui-pr-devicetests

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

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).

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 a layout alignment edge case where Center and End alignment could apply a negative offset when a view’s DesiredSize (which includes margins) exceeds the available bounds, causing the arranged position to “reverse” past the start/margin position.

Changes:

  • Clamp the computed alignment “available space” to >= 0 for horizontal and vertical alignment calculations in LayoutExtensions.
  • Add unit tests to verify Center/End alignment does not reverse positioning when margins make DesiredSize larger than the bounds.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Core/src/Layouts/LayoutExtensions.cs Clamps available alignment space to prevent negative offsets for Center/End when desired > bounds.
src/Core/tests/UnitTests/Layouts/LayoutExtensionTests.cs Adds regression tests covering vertical and horizontal margin-exceeds-bounds alignment behavior.

@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 5, 2026
Copilot AI review requested due to automatic review settings September 2, 2026 06:27

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.

🟡 Changes recommended

The new clamp conditions still miss cases where overflow is caused solely by bottom/right margins, so the original “reverse past Start” behavior can still occur.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

src/Core/src/Layouts/LayoutExtensions.cs:136

  • The margin-overflow clamp only triggers when margin.Top > 0, so the “alignment reverses past Start” bug still occurs when the overflow is caused solely by the bottom margin (e.g., Margin="0,0,0,40" with Center/End). The existing desiredHeight - margin.VerticalThickness <= bounds.Height already limits the clamp to cases where only margins (not the content size) cause the overflow, so the margin.Top > 0 guard can be removed without changing the oversized-content behavior.
			if (view.Parent is not IFlexLayout && availableHeight < 0 && margin.Top > 0 &&
				desiredHeight - margin.VerticalThickness <= bounds.Height)

src/Core/tests/UnitTests/Layouts/LayoutExtensionTests.cs:88

  • This test only covers overflow caused by Margin.Left. Adding a right-margin case here will guard against regressions where only Margin.Right causes DesiredSize to exceed bounds (which previously could also produce a negative offset for Center/End).
			element.Margin.Returns(new Thickness(40, 0, 0, 0));
			element.DesiredSize.Returns(new Size(60, 20));
			element.HorizontalLayoutAlignment.Returns(layoutAlignment);

			var frame = element.ComputeFrame(new Rect(0, 0, 40, 40));

			Assert.Equal(40, frame.Left);
		}
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

double frameX = startX + startMargin;
var availableWidth = boundsWidth - desiredWidth;

if (clampMarginOverflow && availableWidth < 0 && startMargin > 0 && desiredWidth - startMargin - endMargin <= boundsWidth)
Comment on lines +72 to +73
Assert.Equal(40, frame.Top);
}
@kubaflo

This comment has been minimized.

@kubaflo

kubaflo commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@github-actions github-actions Bot added the s/agent-review-in-progress AI review is currently running for this PR label Sep 2, 2026

@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 — 1 findings

See inline comments for details.

Assert.Equal(0, frame.Width);
}

[Theory]

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.

🔍 AI-Generated Review (multi-model)

⚠️ [moderate] Regression Prevention and Test Coverage — The new margin-overflow clamp branch is covered only by clamp-hit cases. Add a discriminating negative-case test where Parent is IFlexLayout (the explicit exemption) and assert Center and End keep the pre-clamp offset path, so this guard cannot over-block valid FlexLayout alignment.

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

AI Review Summary

@SyedAbdulAzeemSF4852 — new AI review results are available based on commit e307e34.

Gate Passed Confidence Low Platform iOS


🗂️ Review Sessions — click to expand
🚦 Gate — Test Before & After Fix

Gate Result: ✅ PASSED

Platform: IOS · Base: main · Merge base: ab4b621b

Test Without Fix (expect FAIL) With Fix (expect PASS)
🧪 LayoutExtensionTests LayoutExtensionTests ✅ FAIL — 30s ✅ PASS — 8s
🔴 Without fix — 🧪 LayoutExtensionTests: FAIL ✅ · 30s

Error-relevant lines (filtered from the build log):

     at Microsoft.Maui.UnitTests.Layouts.LayoutExtensionTests.HorizontalAlignmentDoesNotReverseWhenMarginExceedsBounds(LayoutAlignment layoutAlignment) in /_/src/Core/tests/UnitTests/Layouts/LayoutExtensionTests.cs:line 87
   at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at InvokeStub_LayoutExtensionTests.HorizontalAlignmentDoesNotReverseWhenMarginExceedsBounds(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at Microsoft.Maui.UnitTests.Layouts.LayoutExtensionTests.VerticalAlignmentDoesNotReverseWhenMarginExceedsBounds(LayoutAlignment layoutAlignment) in /_/src/Core/tests/UnitTests/Layouts/LayoutExtensionTests.cs:line 72
   at InvokeStub_LayoutExtensionTests.VerticalAlignmentDoesNotReverseWhenMarginExceedsBounds(Object, Span`1)
🟢 With fix — 🧪 LayoutExtensionTests: PASS ✅ · 8s

(no coded error found; showing last 1200 chars)

 expectedWidth: 100) [3 ms]
  Passed FrameAccountsForHorizontalLayoutAlignment(layoutAlignment: End, offset: {X=0 Y=0}, margin: Microsoft.Maui.Thickness, expectedX: 100, expectedWidth: 100) [< 1 ms]
  Passed FrameAccountsForHorizontalLayoutAlignment(layoutAlignment: Start, offset: {X=10 Y=10}, margin: Microsoft.Maui.Thickness, expectedX: 10, expectedWidth: 100) [< 1 ms]
  Passed FrameAccountsForHorizontalLayoutAlignment(layoutAlignment: Center, offset: {X=10 Y=10}, margin: Microsoft.Maui.Thickness, expectedX: 110, expectedWidth: 100) [< 1 ms]
[xUnit.net 00:00:00.41]   Finished:    Microsoft.Maui.UnitTests
  Passed FrameAccountsForHorizontalLayoutAlignment(layoutAlignment: End, offset: {X=10 Y=10}, margin: Microsoft.Maui.Thickness, expectedX: 210, expectedWidth: 100) [< 1 ms]
  Passed FrameAccountsForHorizontalLayoutAlignment(layoutAlignment: Fill, offset: {X=10 Y=10}, margin: Microsoft.Maui.Thickness, expectedX: 10, expectedWidth: 300) [< 1 ms]
  Passed HeightOverridesFill [1 ms]
  Passed WidthOverridesFill [< 1 ms]
  Passed DesiredSizeIncludesMargin [4 ms]
  Passed MaxWidthOverridesFromCenter [< 1 ms]
Test Run Successful.
Total tests: 74
     Passed: 74
 Total time: 0.8778 Seconds
📁 Fix files reverted (1 files)
  • src/Core/src/Layouts/LayoutExtensions.cs

📋 Pre-Flight — Context & Validation

Pre-Flight: PR #37080

Context

  • PR: Fix irregular placement of views with margins
  • Issue: #8324, Irregular placement of views with margins
  • Platform requested for this phase: iOS
  • Materialized branch: pr-review-37080 at 6d1d3de8ed, based on origin/main at ab4b621b7f
  • Gate: Passed previously. LayoutExtensionTests failed without the production fix (4 new-theory cases) and passed with it (74/74). The gate must not be rerun.
  • Regression cross-reference: Clean; no labeled recent bug-fix PR overlap was reported.

Problem

IView.DesiredSize includes margins. AlignHorizontal and AlignVertical add the leading margin to the frame origin, then use bounds - desiredSize as the Center/End alignment offset. When intrinsic content fits but a positive leading margin makes the margin-inclusive desired size exceed the bounds, that offset becomes negative and moves the view backward from its Start-aligned, margin-adjusted origin. #8324 demonstrates this with a 20-point child, a 40-point top margin, and a 40-point-high horizontal stack.

Current PR Diff

The PR changes:

  1. src/Core/src/Layouts/LayoutExtensions.cs
    • Computes horizontal/vertical available space once.
    • Replaces the negative available space with zero only when the leading margin is positive, the intrinsic size (desiredSize - total margins) still fits the bounds, and the parent is not IFlexLayout.
    • Passes a clampMarginOverflow flag into the horizontal scalar helper.
  2. src/Core/tests/UnitTests/Layouts/LayoutExtensionTests.cs
    • Adds Center/End theories for horizontal and vertical leading-margin overflow, each expecting the frame origin to remain at 40.

The initial PR revision used an unconditional Math.Max(0, bounds - desiredSize). Review and UI evidence showed that this changed zero-margin oversized Center/End behavior, explicit Fill-to-Center overflow, and FlexLayout placement on all platforms. The current revision narrows the clamp to margin-attributable overflow and excludes FlexLayout.

Candidate Requirements

  • Each candidate must use a mechanism meaningfully different from both the original unconditional clamp and the current parent/type-and-size conditional clamp.
  • The only production file safely revertible by the try-fix baseline is src/Core/src/Layouts/LayoutExtensions.cs; the PR test file remains in place and is read-only during attempts.
  • Preserve existing oversized zero-margin Center/End semantics, explicit Fill-to-Center behavior, and FlexLayout behavior.
  • Keep the layout hot path allocation-free and avoid public API changes.
  • One implementation/test pass and at most one focused correction/retest per candidate.

Test Scope

Run only:

dotnet test src/Core/tests/UnitTests/Core.UnitTests.csproj --filter "LayoutExtensionTests"

This class filter is the detected primary test and includes the new four regression cases plus the existing alignment/Fill coverage. No additional mandatory regression tests were supplied for STEP 5a, and no full suite may be run.


🔬 Code Review — Deep Analysis

Code Review — PR #37080

Independent Assessment

What this changes: ComputeFrame now suppresses negative Center/End alignment slack only when a positive leading margin is solely responsible for the overflow, the margin-free child still fits in the available bounds, and the parent is not IFlexLayout. The horizontal and vertical paths remain allocation-free and preserve negative slack for genuinely oversized content.

Inferred motivation: DesiredSize includes margins, so a fitting child with a large leading margin can otherwise receive a negative Center/End offset that moves it behind its Start-aligned margin anchor.

Approach assessment: The narrowed predicate is materially safer than an unconditional Math.Max(0, bounds - desiredSize). It preserves zero-margin oversized placement, trailing-margin-only placement, explicit Fill-to-Center overflow, and FlexLayout's established positioning. The shared implementation is the correct abstraction layer and introduces no public API or startup/state changes.

Reconciliation with PR Narrative

The current implementation agrees with the stated root cause and fixes #8324's margin-driven reversal. The description's high-level claim is accurate, although it omits the important safeguards now present in the submitted code: intrinsic-size fit, positive leading margin, and the IFlexLayout exemption.

Prior Review Reconciliation

Prior finding Status Evidence
Unconditional clamping changes genuinely oversized Center/End and Fill-to-Center behavior ✅ Fixed The current predicate clamps only when desiredSize - totalMargins <= bounds, so genuine intrinsic overflow retains negative slack.
Shared clamp caused FlexLayout visual regressions ✅ Fixed in code Both axes bypass the clamp when view.Parent is IFlexLayout.
New tests did not discriminate the intended branch from adjacent overflow behavior ⚠️ Partially unresolved The narrowed implementation protects adjacent behavior, but no new test exercises the explicit FlexLayout bypass.
Earlier deep UI failures on commit 850563f 🔄 Obsolete for the current implementation Those reports evaluated the prior unconditional-clamp revision. Current-head checks were still in progress when reviewed, so current deep-UI coverage is not yet conclusive.

Blast Radius Assessment

  • Runs for all instances: ComputeFrame is shared, but the new behavior activates only for Center/End (including eligible Fill-to-Center) with margin-attributable negative slack on a non-Flex parent.
  • Startup impact: None.
  • Static/shared state: None.
  • Hot path: Yes; the change adds only scalar arithmetic, comparisons, and one parent type check, with no allocations or iteration.

CI Status

  • Trusted Gate: ✅ Passed — the four new regression cases fail without the production fix and all 74 LayoutExtensionTests pass with it.
  • Current PR head: Anonymous current-head evidence showed checks still in progress; required-check membership could not be queried without authentication.
  • Classification: Pending/undetermined. Confidence is therefore capped at low for an as-submitted merge recommendation.

Findings

⚠️ Warning — FlexLayout bypass lacks a discriminating regression test

src/Core/tests/UnitTests/Layouts/LayoutExtensionTests.cs:60 covers only cases where the clamp activates. Add horizontal and vertical Center/End cases with an IFlexLayout parent and assert the pre-clamp negative-slack positions. Without this negative case, a future simplification can remove the explicit exemption while the new tests remain green.

The raw inline finding is persisted in inline-findings.json.

Failure-Mode Probing

  • Genuinely oversized child with no margin: The leading-margin predicate is false, so Center/End retain their negative offsets.
  • Trailing-margin-only overflow: startMargin > 0 / margin.Top > 0 is false, so existing alignment behavior is unchanged.
  • Fill normalized to Center with explicit size larger than bounds: The margin-free size does not fit, so the clamp does not activate.
  • FlexLayout parent: The type guard bypasses the clamp, preserving FlexLayout behavior; this path is not pinned by the submitted tests.
  • Null parent: null is not IFlexLayout is true, so a detached/substituted view follows the ordinary non-Flex path without dereference.

External Output Contract

Not applicable.

Verdict: NEEDS_DISCUSSION

Confidence: low

Summary: The production fix is narrowly scoped and no blocking implementation defect was found. The explicit FlexLayout compatibility branch needs a discriminating negative test, and current-head CI remained pending; both prevent an LGTM for the raw submitted candidate.


🛠️ Try-Fix — Analysis & Comparison

STEP 5a Try-Fix Aggregate

Candidate 1 — Margin-Neutral Slack with Oversize Guard

Model: gpt-5.3-codex

Result: Blocked

Approach

Compute Center/End alignment slack from intrinsic content size (DesiredSize minus margins) rather than margin-inclusive desired size, with an oversize guard and a FlexLayout bypass. This treats margin contribution as the source of artificial negative slack rather than clamping an already-computed negative result.

Difference from Prior Approaches

  • Avoids the current PR's conditional post-computation clamp based on leading margin, intrinsic fit, and IFlexLayout parent type.
  • Avoids the rejected unconditional Math.Max(0, bounds - desiredSize) clamp.
  • Uses margin-neutral alignment input while preserving negative slack for genuine intrinsic-content overflow.

Diff

No diff was produced. The attempt was blocked before tracked-file edits.

Test Result

The required command was:

dotnet test src/Core/tests/UnitTests/Core.UnitTests.csproj --filter "LayoutExtensionTests"

It was not run because the mandatory baseline could not be established.

Failure Analysis

pwsh .github/scripts/EstablishBrokenBaseline.ps1 rejected the pre-existing dirty tracked worktree and did not create .github/.baseline-state.json. Without that state and its RevertedFiles allow-list, the try-fix contract prohibits implementation or testing. Inline self-review recorded zero findings because there was no attempt diff. The exact restore command ran and reported that no baseline state existed, which is the accepted no-edit blocked path.

Artifacts: CustomAgentLogsTmp/PRState/37080/PRAgent/try-fix/attempt-1/ and CustomAgentLogsTmp/PRState/37080/PRAgent/try-fix-1/content.md

Candidate 2 — Final-Origin Margin Constraint

Model: gpt-5.6-sol

Result: Blocked

Approach

Keep the existing margin-inclusive Center/End calculation as the preferred position, then treat a positive leading margin as a positional invariant: a genuine Center/End result cannot move behind the Start-aligned margin anchor (bounds.X + margin.Left or bounds.Y + margin.Top). Apply that invariant only to authored Center/End alignment on non-Flex parents, preserving zero-margin oversized placement, Fill-to-Center conversion, and FlexLayout paths.

Difference from Prior Approaches

  • Does not replace negative slack conditionally as the current PR does.
  • Does not unconditionally clamp all negative slack as the rejected initial revision did.
  • Does not recompute slack from intrinsic content size as candidate 1 proposed.
  • Leaves desired size and free-space arithmetic intact, constraining only the final preferred coordinate against the leading-margin anchor.

Diff

No diff was produced. The attempt was blocked before tracked-file edits.

Test Result

The required command was:

dotnet test src/Core/tests/UnitTests/Core.UnitTests.csproj --filter "LayoutExtensionTests"

It was not run because the mandatory baseline could not be established.

Failure Analysis

pwsh .github/scripts/EstablishBrokenBaseline.ps1 again rejected the pre-existing dirty tracked worktree and did not create .github/.baseline-state.json. The missing RevertedFiles allow-list made implementation and empirical testing unsafe. Inline self-review recorded zero findings because there was no attempt diff. The exact restore command ran and reported that no baseline state existed, which is the accepted no-edit blocked path.

Artifacts: CustomAgentLogsTmp/PRState/37080/PRAgent/try-fix/attempt-2/ and CustomAgentLogsTmp/PRState/37080/PRAgent/try-fix-2/content.md

Aggregate Outcome

Two bounded, mechanism-distinct candidates were generated, but neither could be implemented or tested. Both are proposals only, not passing alternatives. The shared blocker is the pre-existing dirty tracked worktree, which prevents the required baseline script from creating the restoration state and edit allow-list.


📝 PR Finalize — Recommended Title & Description

Assessment: ✏️ Recommend updating — the current title is not component-scoped, and the description inaccurately implies an unconditional clamp while omitting the intrinsic-size, leading-margin, and FlexLayout safeguards present in the submitted PR.

Recommended title

[Core] Layout: Prevent margins from reversing Center and End alignment

Recommended description

### Issue Details

- When a view's margin makes its desired size larger than its parent's available bounds, Center and End alignment can apply a negative offset that moves the view backward past the Start position, causing irregular or visually reversed placement.

### Root Cause

- `DesiredSize` includes the view's margins. When a fitting child's positive leading margin makes the margin-inclusive desired size larger than the available bounds, `boundsWidth - desiredWidth` or `bounds.Height - desiredHeight` becomes negative. Center and End then apply that negative value as an offset, moving the view behind its margin-adjusted Start position.

### Description of Change

- In `LayoutExtensions.ComputeFrame`, clamp negative horizontal or vertical alignment space to zero only when the positive leading margin causes the overflow and the margin-free child still fits within the bounds.
- Preserve existing negative-offset behavior for genuinely oversized content, trailing-margin-only overflow, and Fill alignment normalized to Center.
- Preserve FlexLayout placement by bypassing the clamp when the parent implements `IFlexLayout`.
- Add horizontal and vertical regression coverage for Center and End alignment with leading-margin overflow.
- Reference: [Legacy `Layout.cs` alignment behavior](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed

Fixes #8324

### Validated the behaviour in the following platforms

- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output

| Platform | Before | After |
|----------|--------|-------|
| iOS | <img src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978"> | <img src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3"> |
| Mac | <img src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395"> | <img src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa"> |
| Windows | <img src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87"> | <img src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015"> |
| Android | <img src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a"> | <img src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36"> |

🏁 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Winner: pr-plus-reviewer

pr-plus-reviewer is the strongest candidate because it preserves the submitted production fix and adds the expert reviewer's missing discriminating coverage for the explicit IFlexLayout bypass. Its required targeted validation passed with 78/78 tests, while the raw PR passed its trusted Gate with 74/74 but leaves that compatibility branch unpinned.

Comparative Ranking

Rank Candidate Implementation Regression evidence Expert assessment Decision
1 pr-plus-reviewer Raw PR production fix plus four FlexLayout negative-case assertions ✅ 78 passed, 0 failed, 0 skipped Resolves the sole current expert warning without changing runtime behavior Winner
2 pr Conditional margin-overflow clamp with intrinsic-fit, leading-margin, and non-Flex guards ✅ Trusted Gate: tests fail without the fix and 74/74 pass with it Production approach is sound; ⚠️ explicit FlexLayout exemption lacks a discriminating test Viable, but weaker coverage
3 try-fix-1 Proposed margin-neutral slack with an oversize guard ⚪ Blocked before implementation; required test not run Mechanistically plausible, but no diff or empirical evidence Cannot outrank passing candidates
4 try-fix-2 Proposed final-origin constraint against the leading-margin anchor ⚪ Blocked before implementation; required test not run Mechanistically distinct, but no diff or empirical evidence Cannot outrank passing candidates

Production Fix Assessment

The submitted implementation addresses #8324 at the shared layout layer without allocations or public API changes. Unlike the earlier unconditional clamp, it preserves genuinely oversized Center/End placement, explicit Fill-to-Center overflow, trailing-margin-only behavior, and FlexLayout positioning. Earlier major review findings and deep-UI regressions were tied to that broader revision and are addressed by the current predicate.

Why the Raw PR Does Not Win

The production logic contains an explicit view.Parent is not IFlexLayout compatibility boundary introduced to prevent observed cross-platform FlexLayout regressions. The submitted tests cover only clamp-hit cases, so they remain green if that bypass is accidentally removed. The winning candidate adds the missing negative cases and passes the exact required class-level validation.

Validation and Uncertainty

  • Trusted Gate for pr: ✅ passed; do not rerun.
  • Targeted validation for pr-plus-reviewer: ✅ 78/78 passed from the required sandbox.
  • try-fix-1 and try-fix-2: blocked before edits and testing, so both remain proposals rather than validated candidates.
  • Current GitHub checks for the live PR head were still in progress during review, and anonymous access could not identify required-check membership. This does not overturn the candidate comparison, but final merge readiness remains contingent on current-head CI completion.

Because pr-plus-reviewer, not the raw submitted PR, wins, the required recommendation is REQUEST CHANGES.


📱 UI Tests — Button,Label,Layout

Detected UI test categories: Button,Label,Layout

✅ Deep UI tests — 355 passed, 0 failed, 8 skipped across 3 categories on platform-pool agent (replaces in-process counts above).

🧪 UI Test Execution Results (deep, platform pool)

Category Tests Snapshot diffs
Button 71/72 (1 skipped) ✓ —
Label 90/92 (2 skipped) ✓ —
Layout 194/199 (5 skipped) ✓ —
📎 Download drop-deep-uitests artifact (TRX + snapshot diffs)

🧭 Next Steps — reviewer changes required

The reviewer-enhanced candidate identified changes that are not yet in the submitted PR.

Why: The submitted production fix is narrowly scoped and passes its trusted Gate, but the expert reviewer found that its explicit FlexLayout exemption lacked a discriminating regression test. pr-plus-reviewer adds horizontal and vertical Center/End coverage for that bypass and passes all 78 targeted tests without changing runtime code.

Address the actionable findings in this review before merging.

@MauiBot MauiBot removed the s/agent-review-in-progress AI review is currently running for this PR label Sep 2, 2026
@kubaflo
kubaflo changed the base branch from main to inflight/current September 2, 2026 22:43
@kubaflo
kubaflo merged commit b6d41bd into dotnet:inflight/current Sep 2, 2026
128 of 144 checks passed
@github-actions github-actions Bot added this to the .NET 11.0-preview7 milestone Sep 2, 2026
kubaflo pushed 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!

### Issue Details
- When a view’s margin makes its desired size larger than its parent’s
available bounds, Center and End alignment apply a negative offset that
moves the view backward past the Start position, causing irregular or
visually reversed placement.

### Root Cause
- DesiredSize includes the view’s margins. When those margins make the
desired size larger than the available bounds, boundsWidth -
desiredWidth or bounds.Height - desiredHeight becomes negative. Center
and End alignment then use that negative value as an offset, moving the
view backward past its Start position and visually reversing the layout.

### Description of Change
- Clamp the available alignment space to a minimum of zero in
AlignHorizontal and AlignVertical. When a view’s desired size exceeds
its bounds, Center and End no longer apply a negative offset and instead
retain the margin-adjusted Start position.
- Reference =>
[Layout.cs](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed
Fixes #8324

### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
| Platform | Before | After |
|----------|----------|----------|
| iOS | <img
src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978">
| <img
src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3">
|
| Mac | <img
src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395">
| <img
src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa">
|
| Windows | <img
src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87">
| <img
src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015">
|
| Android | <img
src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a">
| <img
src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36">
|
kubaflo pushed 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!

### Issue Details
- When a view’s margin makes its desired size larger than its parent’s
available bounds, Center and End alignment apply a negative offset that
moves the view backward past the Start position, causing irregular or
visually reversed placement.

### Root Cause
- DesiredSize includes the view’s margins. When those margins make the
desired size larger than the available bounds, boundsWidth -
desiredWidth or bounds.Height - desiredHeight becomes negative. Center
and End alignment then use that negative value as an offset, moving the
view backward past its Start position and visually reversing the layout.

### Description of Change
- Clamp the available alignment space to a minimum of zero in
AlignHorizontal and AlignVertical. When a view’s desired size exceeds
its bounds, Center and End no longer apply a negative offset and instead
retain the margin-adjusted Start position.
- Reference =>
[Layout.cs](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed
Fixes #8324

### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
| Platform | Before | After |
|----------|----------|----------|
| iOS | <img
src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978">
| <img
src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3">
|
| Mac | <img
src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395">
| <img
src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa">
|
| Windows | <img
src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87">
| <img
src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015">
|
| Android | <img
src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a">
| <img
src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36">
|
kubaflo pushed 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!

### Issue Details
- When a view’s margin makes its desired size larger than its parent’s
available bounds, Center and End alignment apply a negative offset that
moves the view backward past the Start position, causing irregular or
visually reversed placement.

### Root Cause
- DesiredSize includes the view’s margins. When those margins make the
desired size larger than the available bounds, boundsWidth -
desiredWidth or bounds.Height - desiredHeight becomes negative. Center
and End alignment then use that negative value as an offset, moving the
view backward past its Start position and visually reversing the layout.

### Description of Change
- Clamp the available alignment space to a minimum of zero in
AlignHorizontal and AlignVertical. When a view’s desired size exceeds
its bounds, Center and End no longer apply a negative offset and instead
retain the margin-adjusted Start position.
- Reference =>
[Layout.cs](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed
Fixes #8324

### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
| Platform | Before | After |
|----------|----------|----------|
| iOS | <img
src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978">
| <img
src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3">
|
| Mac | <img
src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395">
| <img
src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa">
|
| Windows | <img
src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87">
| <img
src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015">
|
| Android | <img
src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a">
| <img
src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36">
|
kubaflo pushed 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!

### Issue Details
- When a view’s margin makes its desired size larger than its parent’s
available bounds, Center and End alignment apply a negative offset that
moves the view backward past the Start position, causing irregular or
visually reversed placement.

### Root Cause
- DesiredSize includes the view’s margins. When those margins make the
desired size larger than the available bounds, boundsWidth -
desiredWidth or bounds.Height - desiredHeight becomes negative. Center
and End alignment then use that negative value as an offset, moving the
view backward past its Start position and visually reversing the layout.

### Description of Change
- Clamp the available alignment space to a minimum of zero in
AlignHorizontal and AlignVertical. When a view’s desired size exceeds
its bounds, Center and End no longer apply a negative offset and instead
retain the margin-adjusted Start position.
- Reference =>
[Layout.cs](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed
Fixes #8324

### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
| Platform | Before | After |
|----------|----------|----------|
| iOS | <img
src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978">
| <img
src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3">
|
| Mac | <img
src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395">
| <img
src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa">
|
| Windows | <img
src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87">
| <img
src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015">
|
| Android | <img
src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a">
| <img
src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36">
|
kubaflo pushed 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!

### Issue Details
- When a view’s margin makes its desired size larger than its parent’s
available bounds, Center and End alignment apply a negative offset that
moves the view backward past the Start position, causing irregular or
visually reversed placement.

### Root Cause
- DesiredSize includes the view’s margins. When those margins make the
desired size larger than the available bounds, boundsWidth -
desiredWidth or bounds.Height - desiredHeight becomes negative. Center
and End alignment then use that negative value as an offset, moving the
view backward past its Start position and visually reversing the layout.

### Description of Change
- Clamp the available alignment space to a minimum of zero in
AlignHorizontal and AlignVertical. When a view’s desired size exceeds
its bounds, Center and End no longer apply a negative offset and instead
retain the margin-adjusted Start position.
- Reference =>
[Layout.cs](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed
Fixes #8324

### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
| Platform | Before | After |
|----------|----------|----------|
| iOS | <img
src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978">
| <img
src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3">
|
| Mac | <img
src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395">
| <img
src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa">
|
| Windows | <img
src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87">
| <img
src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015">
|
| Android | <img
src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a">
| <img
src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36">
|
kubaflo pushed 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!

### Issue Details
- When a view’s margin makes its desired size larger than its parent’s
available bounds, Center and End alignment apply a negative offset that
moves the view backward past the Start position, causing irregular or
visually reversed placement.

### Root Cause
- DesiredSize includes the view’s margins. When those margins make the
desired size larger than the available bounds, boundsWidth -
desiredWidth or bounds.Height - desiredHeight becomes negative. Center
and End alignment then use that negative value as an offset, moving the
view backward past its Start position and visually reversing the layout.

### Description of Change
- Clamp the available alignment space to a minimum of zero in
AlignHorizontal and AlignVertical. When a view’s desired size exceeds
its bounds, Center and End no longer apply a negative offset and instead
retain the margin-adjusted Start position.
- Reference =>
[Layout.cs](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed
Fixes #8324

### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
| Platform | Before | After |
|----------|----------|----------|
| iOS | <img
src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978">
| <img
src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3">
|
| Mac | <img
src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395">
| <img
src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa">
|
| Windows | <img
src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87">
| <img
src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015">
|
| Android | <img
src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a">
| <img
src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36">
|
kubaflo pushed 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!

### Issue Details
- When a view’s margin makes its desired size larger than its parent’s
available bounds, Center and End alignment apply a negative offset that
moves the view backward past the Start position, causing irregular or
visually reversed placement.

### Root Cause
- DesiredSize includes the view’s margins. When those margins make the
desired size larger than the available bounds, boundsWidth -
desiredWidth or bounds.Height - desiredHeight becomes negative. Center
and End alignment then use that negative value as an offset, moving the
view backward past its Start position and visually reversing the layout.

### Description of Change
- Clamp the available alignment space to a minimum of zero in
AlignHorizontal and AlignVertical. When a view’s desired size exceeds
its bounds, Center and End no longer apply a negative offset and instead
retain the margin-adjusted Start position.
- Reference =>
[Layout.cs](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed
Fixes #8324

### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
| Platform | Before | After |
|----------|----------|----------|
| iOS | <img
src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978">
| <img
src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3">
|
| Mac | <img
src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395">
| <img
src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa">
|
| Windows | <img
src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87">
| <img
src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015">
|
| Android | <img
src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a">
| <img
src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36">
|
kubaflo pushed 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!

### Issue Details
- When a view’s margin makes its desired size larger than its parent’s
available bounds, Center and End alignment apply a negative offset that
moves the view backward past the Start position, causing irregular or
visually reversed placement.

### Root Cause
- DesiredSize includes the view’s margins. When those margins make the
desired size larger than the available bounds, boundsWidth -
desiredWidth or bounds.Height - desiredHeight becomes negative. Center
and End alignment then use that negative value as an offset, moving the
view backward past its Start position and visually reversing the layout.

### Description of Change
- Clamp the available alignment space to a minimum of zero in
AlignHorizontal and AlignVertical. When a view’s desired size exceeds
its bounds, Center and End no longer apply a negative offset and instead
retain the margin-adjusted Start position.
- Reference =>
[Layout.cs](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed
Fixes #8324

### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
| Platform | Before | After |
|----------|----------|----------|
| iOS | <img
src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978">
| <img
src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3">
|
| Mac | <img
src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395">
| <img
src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa">
|
| Windows | <img
src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87">
| <img
src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015">
|
| Android | <img
src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a">
| <img
src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36">
|
kubaflo pushed a commit that referenced this pull request Sep 21, 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!

### Issue Details
- When a view’s margin makes its desired size larger than its parent’s
available bounds, Center and End alignment apply a negative offset that
moves the view backward past the Start position, causing irregular or
visually reversed placement.

### Root Cause
- DesiredSize includes the view’s margins. When those margins make the
desired size larger than the available bounds, boundsWidth -
desiredWidth or bounds.Height - desiredHeight becomes negative. Center
and End alignment then use that negative value as an offset, moving the
view backward past its Start position and visually reversing the layout.

### Description of Change
- Clamp the available alignment space to a minimum of zero in
AlignHorizontal and AlignVertical. When a view’s desired size exceeds
its bounds, Center and End no longer apply a negative offset and instead
retain the margin-adjusted Start position.
- Reference =>
[Layout.cs](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed
Fixes #8324

### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
| Platform | Before | After |
|----------|----------|----------|
| iOS | <img
src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978">
| <img
src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3">
|
| Mac | <img
src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395">
| <img
src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa">
|
| Windows | <img
src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87">
| <img
src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015">
|
| Android | <img
src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a">
| <img
src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36">
|
kubaflo pushed a commit that referenced this pull request Sep 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!

### Issue Details
- When a view’s margin makes its desired size larger than its parent’s
available bounds, Center and End alignment apply a negative offset that
moves the view backward past the Start position, causing irregular or
visually reversed placement.

### Root Cause
- DesiredSize includes the view’s margins. When those margins make the
desired size larger than the available bounds, boundsWidth -
desiredWidth or bounds.Height - desiredHeight becomes negative. Center
and End alignment then use that negative value as an offset, moving the
view backward past its Start position and visually reversing the layout.

### Description of Change
- Clamp the available alignment space to a minimum of zero in
AlignHorizontal and AlignVertical. When a view’s desired size exceeds
its bounds, Center and End no longer apply a negative offset and instead
retain the margin-adjusted Start position.
- Reference =>
[Layout.cs](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed
Fixes #8324

### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
| Platform | Before | After |
|----------|----------|----------|
| iOS | <img
src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978">
| <img
src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3">
|
| Mac | <img
src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395">
| <img
src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa">
|
| Windows | <img
src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87">
| <img
src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015">
|
| Android | <img
src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a">
| <img
src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36">
|
kubaflo pushed a commit that referenced this pull request Sep 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!

### Issue Details
- When a view’s margin makes its desired size larger than its parent’s
available bounds, Center and End alignment apply a negative offset that
moves the view backward past the Start position, causing irregular or
visually reversed placement.

### Root Cause
- DesiredSize includes the view’s margins. When those margins make the
desired size larger than the available bounds, boundsWidth -
desiredWidth or bounds.Height - desiredHeight becomes negative. Center
and End alignment then use that negative value as an offset, moving the
view backward past its Start position and visually reversing the layout.

### Description of Change
- Clamp the available alignment space to a minimum of zero in
AlignHorizontal and AlignVertical. When a view’s desired size exceeds
its bounds, Center and End no longer apply a negative offset and instead
retain the margin-adjusted Start position.
- Reference =>
[Layout.cs](https://github.com/dotnet/maui/blob/a1521eda4980d8b6a890323ee3273e2e96f71703/src/Controls/src/Core/LegacyLayouts/Layout.cs#L259)

### Issues Fixed
Fixes #8324

### Validated the behaviour in the following platforms
- [x] Windows
- [x] Android
- [x] iOS
- [x] Mac

### Output
| Platform | Before | After |
|----------|----------|----------|
| iOS | <img
src="https://github.com/user-attachments/assets/86c94004-a6dc-480a-abb1-5dbb89f4e978">
| <img
src="https://github.com/user-attachments/assets/5eb63737-4547-4908-8d11-57e175bc74c3">
|
| Mac | <img
src="https://github.com/user-attachments/assets/53479831-a10f-49ce-a78b-8e5b11c95395">
| <img
src="https://github.com/user-attachments/assets/fd6d5a5c-d69b-4e71-ae17-7438d328aefa">
|
| Windows | <img
src="https://github.com/user-attachments/assets/f0a1ad5b-0f55-455e-92db-55a2b63e1e87">
| <img
src="https://github.com/user-attachments/assets/379f63fd-4535-4c9d-a173-7b2db3482015">
|
| Android | <img
src="https://github.com/user-attachments/assets/6d3577e0-d58c-4cd9-a74f-da83644ee16a">
| <img
src="https://github.com/user-attachments/assets/47c32295-64cf-41e2-8f92-8404ba08ff36">
|
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration platform/android platform/ios platform/macos macOS / Mac Catalyst platform/windows s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-fix-win AI found a better alternative fix than the PR 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.

Irregular placement of views with margins

5 participants