Skip to content

[Windows] - Fix Grid layout not updating when Row/Column changed dynamically#30206

Open
prakashKannanSf3972 wants to merge 7 commits intodotnet:mainfrom
prakashKannanSf3972:fix-20404
Open

[Windows] - Fix Grid layout not updating when Row/Column changed dynamically#30206
prakashKannanSf3972 wants to merge 7 commits intodotnet:mainfrom
prakashKannanSf3972:fix-20404

Conversation

@prakashKannanSf3972
Copy link
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!

Root Cause

  • When Grid.Row or Grid.Column properties are updated on a Grid element nested within another Grid, the current implementation only invalidates the element itself and does not propagate the invalidation to its parent. As a result, the parent layout is not re-measured or arranged correctly, leading to inaccurate or incomplete rendering.

Description of Change

  • Improved parent layout invalidation for Grid on Windows to ensure UI updates correctly when Grid.Row or Grid.Column properties change.

Issues Fixed

Fixes #20404

Tested the behaviour in the following platforms

  • Android
  • Windows
  • iOS
  • Mac

Output

Before After
BeforeFix_Grid.mp4
AfterFix_Grid.mp4

@dotnet-policy-service
Copy link
Contributor

Hey there @@prakashKannanSf3972! 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 community ✨ Community Contribution partner/syncfusion Issues / PR's with Syncfusion collaboration labels Jun 25, 2025
@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jsuarezruiz
Copy link
Contributor

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@prakashKannanSf3972 prakashKannanSf3972 marked this pull request as ready for review June 27, 2025 07:02
Copilot AI review requested due to automatic review settings June 27, 2025 07:02
@prakashKannanSf3972 prakashKannanSf3972 requested a review from a team as a code owner June 27, 2025 07:02
Copy link
Contributor

Copilot AI left a comment

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 ensures that dynamic changes to Grid.Row and Grid.Column on Windows correctly invalidate the parent layout so the UI updates without requiring a window resize.

  • Added a UI sample page in the HostApp for toggling row/column at runtime.
  • Added a cross-platform UI test in TestCases.Shared.Tests to verify dynamic grid updates.
  • Updated Grid.cs to propagate measure invalidation to the parent grid on Windows.

Reviewed Changes

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

File Description
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue20404.cs New UITest verifying dynamic row/column toggles trigger layout updates.
src/Controls/tests/TestCases.HostApp/Issues/Issue20404.cs New sample page with buttons to toggle grid row/column dynamically.
src/Controls/src/Core/Layout/Grid.cs Updated Invalidate method to explicitly invalidate parent grid on Windows.

@MauiBot MauiBot added s/agent-changes-requested AI agent recommends changes - found a better alternative or issues s/agent-gate-failed AI could not verify tests catch the bug s/agent-reviewed PR was reviewed by AI agent workflow (full 4-phase review) labels Mar 21, 2026
@kubaflo
Copy link
Contributor

kubaflo commented Mar 21, 2026

/azp run maui-pr-uitests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@kubaflo kubaflo left a comment

Choose a reason for hiding this comment

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

Could you please review the AI's summary?

@github-actions
Copy link
Contributor

github-actions bot commented Mar 25, 2026

🚀 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 -- 30206

Or

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

@Dhivya-SF4094
Copy link
Contributor

Could you please review the AI's summary?

Validated the AI summary and addressed the concerns accordingly.
Note: The issue linked to this PR has been closed as not planned

@sheiksyedm
Copy link
Contributor

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

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@MauiBot
Copy link
Collaborator

MauiBot commented Mar 27, 2026

🤖 AI Summary

📊 Expand Full Review5e4a947 · Addressed AI summary
🔍 Pre-Flight — Context & Validation

Issue: #20404 - Changing Grid.Row does not update layout until window is resized
PR: #30206 - [Windows] - Fix Grid layout not updating when Row/Column changed dynamically
Platforms Affected: Windows (bug is Windows-only; fix guarded with #if WINDOWS)
Files Changed: 1 implementation, 2 test (+ 8 snapshot PNGs)

Key Findings

  • Bug: When Grid.SetRow()/Grid.SetColumn() is called on a Grid that is a child of another Grid, the parent Grid does not re-measure on Windows, causing the layout to not update until a window resize occurs
  • Root cause: Grid.Invalidate() (the property changed callback for Row/Column/RowSpan/ColumnSpan attached properties) calls grid.InvalidateMeasure() on the child Grid itself, but this invalidation does not propagate to the parent Grid on Windows
  • Fix: In Grid.Invalidate(), a #if WINDOWS block explicitly calls containerGrid.InvalidateMeasure() when the parent is also a Grid
  • Copilot reviewer flagged: (a) symbol correctness for #if WINDOWS, (b) early return skips grid's own InvalidateMeasure() — PR author says concern addressed (the grid.InvalidateMeasure() is called on line before the #if WINDOWS block)
  • Issue Changing Grid.Row does not update layout until window is resized #20404 was closed as "not planned" but this PR is still open addressing it
  • Previous agent review labels: s/agent-gate-failed, s/agent-changes-requested, s/agent-fix-win
  • The test uses VerifyScreenshot() with named snapshots (AfterGridRowToggled, AfterGridColumnToggled) and screenshots are included for Windows, Android, iOS, Mac

Concerns With Fix

  • return inside #if WINDOWS block is unnecessary (the else if wouldn't execute anyway since we're in the if (bindable is Grid) branch), but harmless
  • Only invalidates one level of parent — should be sufficient since InvalidateMeasure() propagates upward
  • Fix is compile-time Windows-only (#if WINDOWS) — appropriate for a Windows-specific behavior difference

Fix Candidates

# Source Approach Test Result Files Changed Notes
PR PR #30206 In Grid.Invalidate(), add #if WINDOWS block to call containerGrid.InvalidateMeasure() when parent is Grid ⏳ PENDING (Gate) Grid.cs Original PR

🚦 Gate — Test Verification

Gate Result: ✅ PASSED

Platform: windows

# Type Test Name Filter
1 UITest DynamicGridRowColumnChangeShouldInvalidate Issue20404
Step Expected Actual Result
Without fix FAIL FAIL (36.09% screenshot diff)
With fix PASS PASS (1/1 tests passed)

🔧 Fix — Analysis & Comparison

Fix Candidates

# Source Approach Test Result Files Changed Notes
1 try-fix (claude-opus-4.6) Change else if → separate if — cross-platform, handles Grid parent only ✅ PASS 1 file Logical flow fix, minimal change
2 try-fix (claude-sonnet-4.6) Add if (grid.Parent is Layout parentLayout) parentLayout.InvalidateMeasure() — cross-platform, handles any Layout parent ✅ PASS 1 file Most general — handles Grid in StackLayout/FlexLayout etc.
3 try-fix (gpt-5.3-codex) Walk full ancestor Grid chain + Windows-specific code ❌ FAIL 1 file 6.51% screenshot diff
4 try-fix (gpt-5.4) Child PropertyChanged observer in parent Grid ❌ FAIL 1 file 6.51% screenshot diff
PR PR #30206 #if WINDOWS block in Invalidate() calls containerGrid.InvalidateMeasure() ✅ PASSED (Gate) 1 file Windows-only compile guard, Grid parent only

Cross-Pollination

Model Round New Ideas? Details
claude-opus-4.6 2 No Solution space covered across all axes
gpt-5.3-codex 2 Marginal Suggested also calling InvalidateArrange() — not needed since InvalidateMeasure() triggers re-arrange
claude-sonnet-4.6 2 No Confirmed root cause: (Parent as VisualElement)?.OnChildMeasureInvalidated fires events only, never calls parent's IView.InvalidateMeasure()
gpt-5.4 2 Minor Suggested recomputing child constraints — not addressing parent invalidation root cause

Exhausted: Yes
Selected Fix: Candidate #2 (Attempt 2, claude-sonnet-4.6) — Cross-platform fix that explicitly calls parentLayout.InvalidateMeasure() for any Layout parent. More general than the PR's Windows-only Grid-only check, no platform guards needed, minimal change.


📋 Report — Final Recommendation

⚠️ Final Recommendation: REQUEST CHANGES

Phase Status

Phase Status Notes
Pre-Flight ✅ COMPLETE Issue #20404, Windows-only layout bug
Gate ✅ PASSED windows — 36.09% diff without fix, 1/1 pass with fix
Try-Fix ✅ COMPLETE 4 attempts, 2 passing (Attempts 1 & 2 superior to PR fix)
Report ✅ COMPLETE

Summary

The PR correctly identifies and fixes a real Windows-specific bug: when Grid.SetRow()/Grid.SetColumn() is called on a child Grid nested inside another Grid, the parent Grid does not re-measure on Windows (unlike iOS/Android which auto-propagate). The fix works. However, a cleaner cross-platform alternative was found during Try-Fix exploration that should be preferred over the PR's #if WINDOWS compile guard.

Root Cause

In Grid.Invalidate() (the property-changed callback for Row, Column, RowSpan, ColumnSpan attached properties), when bindable is Grid, the code calls grid.InvalidateMeasure() on the child but never calls InvalidateMeasure() on the parent. The else if branch that does invalidate the parent is skipped because Grid satisfies the first if condition. Windows' WinUI layout engine does not auto-propagate child invalidation to the parent when only the child's position changes (not its size), while iOS/Android native layout engines handle this automatically.

Fix Quality

The PR's fix (#if WINDOWS) works but has drawbacks:

  1. Uses compile-time platform guard — the bug could theoretically affect other platforms too if their native engines change behavior
  2. Only handles Grid parent — misses cases like Grid nested in StackLayout or FlexLayout
  3. Unnecessary return — inside the #if WINDOWS block after containerGrid.InvalidateMeasure(), the return is harmless but needlessly early-exits from the method

Better alternative found (Attempt 2): Add if (grid.Parent is Layout parentLayout) parentLayout.InvalidateMeasure() inside the existing Grid branch:

if (bindable is Grid grid)
{
    grid.InvalidateMeasure();
    if (grid.Parent is Layout parentLayout)
        parentLayout.InvalidateMeasure();
}
else if (bindable is Element element && element.Parent is Grid parentGrid)
{
    parentGrid.InvalidateMeasure();
}

This is:

  • ✅ Cross-platform (no #if WINDOWS)
  • ✅ More general (handles Grid inside any Layout, not just Grid-in-Grid)
  • ✅ 2-line addition with no structural changes
  • ✅ Passes all tests on Windows

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

Labels

community ✨ Community Contribution layout-grid partner/syncfusion Issues / PR's with Syncfusion collaboration 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-failed AI could not verify tests catch the bug 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.

Changing Grid.Row does not update layout until window is resized

10 participants