-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Windows] - Fix Grid layout not updating when Row/Column changed dynamically #30206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
prakashKannanSf3972
wants to merge
5
commits into
dotnet:main
Choose a base branch
from
prakashKannanSf3972:fix-20404
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+172
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4a8df9e
Fixed-Grid-Row-Column-Switches
prakashKannanSf3972 afdf606
Added-SnapShots
prakashKannanSf3972 c1daea8
Updated-Fix
prakashKannanSf3972 a4832da
Removed-Unwanted-In-Test
prakashKannanSf3972 9ac6c58
Updated-Compilation-Symbol
prakashKannanSf3972 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+39.2 KB
...rols/tests/TestCases.Android.Tests/snapshots/android/AfterGridColumnToggled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+39.4 KB
...ontrols/tests/TestCases.Android.Tests/snapshots/android/AfterGridRowToggled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
138 changes: 138 additions & 0 deletions
138
src/Controls/tests/TestCases.HostApp/Issues/Issue20404.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[Issue(IssueTracker.Github, 20404, "Dynamic Grid Row/Column changes don't trigger layout update on Windows until window resize", PlatformAffected.UWP)] | ||
public class Issue20404 : TestContentPage | ||
{ | ||
Grid dynamicGrid; | ||
Button toggleRowButton; | ||
Button toggleColumnButton; | ||
|
||
protected override void Init() | ||
{ | ||
Content = CreateMainGrid(); | ||
} | ||
|
||
Grid CreateMainGrid() | ||
{ | ||
Grid mainGrid = new Grid | ||
{ | ||
RowSpacing = 8, | ||
ColumnSpacing = 8, | ||
RowDefinitions = | ||
{ | ||
new RowDefinition { Height = GridLength.Star }, | ||
new RowDefinition { Height = GridLength.Star }, | ||
new RowDefinition { Height = GridLength.Auto }, | ||
new RowDefinition { Height = GridLength.Auto } | ||
}, | ||
ColumnDefinitions = | ||
{ | ||
new ColumnDefinition { Width = GridLength.Star }, | ||
new ColumnDefinition { Width = GridLength.Star } | ||
} | ||
}; | ||
|
||
AddStaticGrids(mainGrid); | ||
AddDynamicGrid(mainGrid); | ||
AddControlButtons(mainGrid); | ||
return mainGrid; | ||
} | ||
|
||
void AddStaticGrids(Grid parent) | ||
{ | ||
Grid topLeft = CreateStaticGrid("Static\n(0,0)", Colors.LightBlue); | ||
Grid.SetRow(topLeft, 0); | ||
Grid.SetColumn(topLeft, 0); | ||
parent.Children.Add(topLeft); | ||
|
||
Grid topRight = CreateStaticGrid("Static\n(0,1)", Colors.LightCoral); | ||
Grid.SetRow(topRight, 0); | ||
Grid.SetColumn(topRight, 1); | ||
parent.Children.Add(topRight); | ||
|
||
Grid bottomLeft = CreateStaticGrid("Static\n(1,0)", Colors.LightGreen); | ||
Grid.SetRow(bottomLeft, 1); | ||
Grid.SetColumn(bottomLeft, 0); | ||
parent.Children.Add(bottomLeft); | ||
} | ||
|
||
Grid CreateStaticGrid(string labelText, Color backgroundColor) | ||
{ | ||
Grid grid = new Grid { BackgroundColor = backgroundColor }; | ||
Label label = new Label | ||
{ | ||
Text = labelText, | ||
HorizontalOptions = LayoutOptions.Center, | ||
VerticalOptions = LayoutOptions.Center, | ||
TextColor = Colors.Black | ||
}; | ||
|
||
grid.Children.Add(label); | ||
return grid; | ||
} | ||
|
||
void AddDynamicGrid(Grid parent) | ||
{ | ||
dynamicGrid = new Grid | ||
{ | ||
BackgroundColor = Colors.DarkBlue, | ||
AutomationId = "DynamicGrid" | ||
}; | ||
|
||
Label label = new Label | ||
{ | ||
Text = "DYNAMIC\nGRID", | ||
TextColor = Colors.White, | ||
FontAttributes = FontAttributes.Bold, | ||
HorizontalOptions = LayoutOptions.Center, | ||
VerticalOptions = LayoutOptions.Center, | ||
AutomationId = "DynamicLabel" | ||
}; | ||
|
||
dynamicGrid.Children.Add(label); | ||
Grid.SetRow(dynamicGrid, 1); | ||
Grid.SetColumn(dynamicGrid, 1); | ||
|
||
parent.Children.Add(dynamicGrid); | ||
} | ||
|
||
void AddControlButtons(Grid parent) | ||
{ | ||
toggleRowButton = new Button | ||
{ | ||
Text = "Toggle Row (Current: 1)", | ||
AutomationId = "ToggleRowButton" | ||
}; | ||
toggleRowButton.Clicked += OnToggleRowClicked; | ||
|
||
toggleColumnButton = new Button | ||
{ | ||
Text = "Toggle Column (Current: 1)", | ||
AutomationId = "ToggleColumnButton" | ||
}; | ||
toggleColumnButton.Clicked += OnToggleColumnClicked; | ||
|
||
StackLayout buttonStack = new StackLayout | ||
{ | ||
Orientation = StackOrientation.Horizontal, | ||
HorizontalOptions = LayoutOptions.Center, | ||
Children = { toggleRowButton, toggleColumnButton } | ||
}; | ||
|
||
Grid.SetRow(buttonStack, 3); | ||
Grid.SetColumnSpan(buttonStack, 2); | ||
parent.Children.Add(buttonStack); | ||
} | ||
|
||
void OnToggleRowClicked(object sender, EventArgs e) | ||
{ | ||
Grid.SetRow(dynamicGrid, 0); | ||
toggleRowButton.Text = $"Toggle Row (Current: 0)"; | ||
} | ||
|
||
void OnToggleColumnClicked(object sender, EventArgs e) | ||
{ | ||
Grid.SetColumn(dynamicGrid, 0); | ||
toggleColumnButton.Text = $"Toggle Column (Current: 0)"; | ||
} | ||
} |
Binary file added
BIN
+18.3 KB
src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/AfterGridColumnToggled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+18.7 KB
src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/AfterGridRowToggled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions
24
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue20404.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using NUnit.Framework; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
|
||
namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
|
||
public class Issue20404 : _IssuesUITest | ||
{ | ||
public Issue20404(TestDevice testDevice) : base(testDevice) { } | ||
|
||
public override string Issue => "Dynamic Grid Row/Column changes don't trigger layout update on Windows until window resize"; | ||
|
||
[Test] | ||
[Category(UITestCategories.Layout)] | ||
public void DynamicGridRowColumnChangeShouldInvalidate() | ||
{ | ||
App.WaitForElement("ToggleRowButton"); | ||
App.Tap("ToggleRowButton"); | ||
VerifyScreenshot("AfterGridRowToggled"); | ||
App.WaitForElement("ToggleColumnButton"); | ||
App.Tap("ToggleColumnButton"); | ||
VerifyScreenshot("AfterGridColumnToggled"); | ||
} | ||
} |
Binary file added
BIN
+12.7 KB
...ntrols/tests/TestCases.WinUI.Tests/snapshots/windows/AfterGridColumnToggled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.6 KB
src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/AfterGridRowToggled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+47.5 KB
src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/AfterGridColumnToggled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+48.1 KB
src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/AfterGridRowToggled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning immediately after invalidating the parent skips the grid's own
InvalidateMeasure
call. To guarantee both the grid and its container are re‐measured, consider callinggrid.InvalidateMeasure()
before or after invalidating the parent instead of exiting early.Copilot uses AI. Check for mistakes.