Skip to content

Commit ccc7a1d

Browse files
Rebase
1 parent ddb3601 commit ccc7a1d

File tree

3 files changed

+50
-58
lines changed

3 files changed

+50
-58
lines changed

src/Controls/tests/TestCases.HostApp/Issues/Issue27666.cs

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -35,60 +35,18 @@ ContentPage CreateRootContentPage()
3535
}
3636
}
3737

38-
public partial class Issue27666 : TestContentPage
38+
public partial class Issue27666 : ContentPage
3939
{
4040
ObservableCollection<string> items;
41-
CollectionView collectionView;
42-
protected override void Init()
43-
{
44-
items = new ObservableCollection<string>(Enumerable.Range(1, 30).Select(i => $"Item {i}"));
45-
Button itemSpacingButton = CreateButton("Update ItemSpacing", "UpdateItemSpacingButton", OnItemSpacingButtonClicked);
46-
47-
collectionView = new CollectionView
48-
{
49-
AutomationId = "ItemsLayoutCollectionView",
50-
ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal),
51-
ItemsSource = items,
52-
ItemTemplate = new DataTemplate(() =>
53-
{
54-
var label = new Label();
55-
label.SetBinding(Label.TextProperty, ".");
56-
return new Border
57-
{
58-
Content = label,
59-
Padding = 10,
60-
Margin = new Thickness(5),
61-
BackgroundColor = Colors.LightGray,
62-
};
63-
})
64-
};
65-
66-
Grid grid = new Grid
67-
{
68-
RowDefinitions =
69-
{
70-
new RowDefinition { Height = GridLength.Auto },
71-
new RowDefinition { Height = GridLength.Star }
72-
},
73-
RowSpacing = 5
74-
};
75-
grid.Add(itemSpacingButton, 0, 0);
76-
grid.Add(collectionView, 0, 1);
77-
78-
Content = grid;
79-
}
8041

81-
Button CreateButton(string text, string automationId, EventHandler onClick)
42+
public Issue27666()
8243
{
83-
return new Button
84-
{
85-
Text = text,
86-
AutomationId = automationId,
87-
Command = new Command(_ => onClick(this, EventArgs.Empty))
88-
};
44+
InitializeComponent();
45+
items = new ObservableCollection<string>(Enumerable.Range(1, 30).Select(i => $"Item {i}"));
46+
collectionView.ItemsSource = items;
8947
}
9048

91-
void OnItemSpacingButtonClicked(object sender, EventArgs e)
49+
private void OnItemSpacingButtonClicked(object sender, EventArgs e)
9250
{
9351
if (collectionView.ItemsLayout is LinearItemsLayout layout)
9452
{
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue27666">
5+
6+
<Grid RowSpacing="5">
7+
<Grid.RowDefinitions>
8+
<RowDefinition Height="Auto"/>
9+
<RowDefinition Height="*"/>
10+
</Grid.RowDefinitions>
11+
12+
<Button Grid.Row="0"
13+
Text="Update ItemSpacing"
14+
AutomationId="UpdateItemSpacingButton"
15+
Clicked="OnItemSpacingButtonClicked"/>
16+
17+
<CollectionView x:Name="collectionView"
18+
Grid.Row="1"
19+
AutomationId="ItemsLayoutCollectionView"
20+
ItemsLayout="HorizontalList">
21+
<CollectionView.ItemTemplate>
22+
<DataTemplate>
23+
<Border Padding="10"
24+
Margin="5"
25+
BackgroundColor="LightGray">
26+
<Label Text="{Binding .}"/>
27+
</Border>
28+
</DataTemplate>
29+
</CollectionView.ItemTemplate>
30+
</CollectionView>
31+
</Grid>
32+
</ContentPage>

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue27666.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@ namespace Microsoft.Maui.TestCases.Tests.Issues;
77
public class Issue27666 : _IssuesUITest
88
{
99
public override string Issue => "Vertical list and Vertical grid pages have different abnormal behaviors when clicking Update after changing the spacing value";
10-
10+
const string UpdateItemSpacingButton = "UpdateItemSpacingButton";
11+
const string ItemsLayoutCollectionView = "ItemsLayoutCollectionView";
12+
const string NavigationButton = "NavigationButton";
1113
public Issue27666(TestDevice device) : base(device) { }
1214

1315
[Test]
1416
[Category(UITestCategories.CollectionView)]
1517
public void VerifySpacingUpdateInItemsLayout()
1618
{
17-
App.WaitForElement("NavigationButton");
18-
App.Tap("NavigationButton");
19-
App.WaitForElement("ItemsLayoutCollectionView");
20-
App.Tap("UpdateItemSpacingButton");
19+
App.WaitForElement(NavigationButton);
20+
App.Tap(NavigationButton);
21+
App.WaitForElement(ItemsLayoutCollectionView);
22+
App.Tap(UpdateItemSpacingButton);
2123
App.TapBackArrow();
22-
App.WaitForElement("NavigationButton");
23-
App.Tap("NavigationButton");
24-
App.WaitForElement("ItemsLayoutCollectionView");
25-
App.Tap("UpdateItemSpacingButton");
26-
App.WaitForElement("ItemsLayoutCollectionView");
24+
App.WaitForElement(NavigationButton);
25+
App.Tap(NavigationButton);
26+
App.WaitForElement(ItemsLayoutCollectionView);
27+
App.Tap(UpdateItemSpacingButton);
28+
App.WaitForElement(ItemsLayoutCollectionView);
2729
}
2830
}

0 commit comments

Comments
 (0)