Skip to content
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

Fix grid not getting invalidated when changing the Height/Width of Row/ColumnDefinitions declared with the short syntax #26046

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
9 changes: 8 additions & 1 deletion src/Controls/src/Core/DefinitionCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ public class DefinitionCollection<T> : IList<T>, ICollection<T> where T : IDefin

internal DefinitionCollection() => _internalList = new List<T>();

internal DefinitionCollection(params T[] items) => _internalList = new List<T>(items);
internal DefinitionCollection(params T[] items)
{
_internalList = new List<T>(items);
foreach (var item in items)
{
(item as IDefinition).SizeChanged += OnItemSizeChanged;
}
}

public void Add(T item)
{
Expand Down
15 changes: 15 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issues25983.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue25983">

<StackLayout>
<Button Text="Resize row" AutomationId="resizeRowButton" Clicked="Button_Clicked"></Button>
<Button Text="Resize column" AutomationId="resizeColumnButton" Clicked="Button2_Clicked"></Button>
<Grid x:Name="grid" AutomationId="grid" RowDefinitions="50,100,200" ColumnDefinitions="100,100">
<Label x:Name="resizeRowResultLabel" AutomationId="resizeRowResultLabel" BackgroundColor="Red" Grid.Row="1" Grid.Column="0"></Label>
<Label x:Name="resizeColumnResultLabel" AutomationId="resizeColumnResultLabel" BackgroundColor="Blue" Grid.Row="2" Grid.Column="1"></Label>
</Grid>
</StackLayout>

</ContentPage>
21 changes: 21 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issues25983.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 25983, "Issue25983 Grid not getting invalidated when changing the Height/Width of Row/ColumnDefinitions declared with the short syntax", PlatformAffected.All)]
public partial class Issue25983 : ContentPage
{
public Issue25983()
{
InitializeComponent();
}

private void Button_Clicked(object sender, EventArgs e)
{
this.grid.RowDefinitions[2].Height = new GridLength(this.grid.RowDefinitions[2].Height.Value + 100, GridUnitType.Absolute);
}

private void Button2_Clicked(object sender, EventArgs e)
{
this.grid.ColumnDefinitions[1].Width = new GridLength(this.grid.ColumnDefinitions[1].Width.Value + 100, GridUnitType.Absolute);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue25983 : _IssuesUITest
{
public Issue25983(TestDevice device) : base(device) { }

public override string Issue => "Issue25983 Grid not getting invalidated when changing the Height/Width of Row/ColumnDefinitions declared with the short syntax";

[Test]
[Category(UITestCategories.Layout)]
public void VerifyGridRowAndColumnSizeInvalidatedCorrectly()
{
var resizeRowButton = App.WaitForElement("resizeRowButton");
var resizeColumnButton = App.WaitForElement("resizeColumnButton");

resizeRowButton.Click();
resizeColumnButton.Click();
Task.Delay(500).Wait();

VerifyScreenshot();
}
}
}