Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Controls/src/Core/Layout/Grid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,16 @@ static void Invalidate(BindableObject bindable, object oldValue, object newValue
if (bindable is Grid grid)
{
grid.InvalidateMeasure();
#if WINDOWS
// Windows requires explicit parent invalidation for Grid.Row/Column/RowSpan/ColumnSpan changes.
// Unlike iOS/Android, Windows doesn't auto-propagate layout invalidation up the hierarchy,
// causing dynamic attached property changes to not arrange its children correctly.
if (grid.Parent is Grid containerGrid)
{
containerGrid.InvalidateMeasure();
return;
}
#endif
}
else if (bindable is Element element && element.Parent is Grid parentGrid)
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 src/Controls/tests/TestCases.HostApp/Issues/Issue20404.cs
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)";
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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");
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading