Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit f5d7e6b

Browse files
jsuarezruizhartez
andauthored
Fix issue changing the ItemsLayout in UWP CollectionView (#13470) fixes #13437
Co-authored-by: E.Z. Hart <hartez@users.noreply.github.com>
1 parent 032dae2 commit f5d7e6b

File tree

5 files changed

+142
-0
lines changed

5 files changed

+142
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<controls:TestContentPage
3+
xmlns="http://xamarin.com/schemas/2014/forms"
4+
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
6+
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d"
9+
x:Class="Xamarin.Forms.Controls.Issues.Issue13437"
10+
Title="Issue 13437">
11+
<ContentPage.Content>
12+
<StackLayout>
13+
<Label
14+
Padding="12"
15+
BackgroundColor="Black"
16+
TextColor="White"
17+
Text="Tap each Button to change the CollectionView ItemsLayout. If in all cases, the ItemsLayout changes correctly, the test has passed."/>
18+
<Button x:Name="ButtonOne"/>
19+
<Button x:Name="ButtonTwo"/>
20+
<Button x:Name="ButtonThree"/>
21+
<Button x:Name="ButtonFour"/>
22+
<CollectionView
23+
x:Name="Collection"
24+
ItemsSource="{Binding Items}">
25+
<CollectionView.ItemTemplate>
26+
<DataTemplate>
27+
<Label
28+
Text="{Binding Text}"
29+
WidthRequest="100"/>
30+
</DataTemplate>
31+
</CollectionView.ItemTemplate>
32+
</CollectionView>
33+
</StackLayout>
34+
</ContentPage.Content>
35+
</controls:TestContentPage>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System.Collections.Generic;
2+
using Xamarin.Forms.CustomAttributes;
3+
using System.Collections.ObjectModel;
4+
5+
#if UITEST
6+
using Xamarin.Forms.Core.UITests;
7+
using Xamarin.UITest;
8+
using NUnit.Framework;
9+
#endif
10+
11+
namespace Xamarin.Forms.Controls.Issues
12+
{
13+
[Issue(IssueTracker.Github, 13437, "[Bug] Changing ItemsLayout of CollectionView at runtime does not work on UWP",
14+
PlatformAffected.UWP)]
15+
public partial class Issue13437 : TestContentPage
16+
{
17+
public Issue13437()
18+
{
19+
#if APP
20+
InitializeComponent();
21+
22+
ButtonOne.Text = "Set Vertical List";
23+
ButtonOne.Command = new Command(() =>
24+
{
25+
SetVerticalList();
26+
});
27+
28+
ButtonTwo.Text = "Set Horizontal List";
29+
ButtonTwo.Command = new Command(() =>
30+
{
31+
SetHorizontalList();
32+
});
33+
34+
ButtonThree.Text = "Set Grid 2 List";
35+
ButtonThree.Command = new Command(() =>
36+
{
37+
SetTwoGrid();
38+
});
39+
40+
ButtonFour.Text = "Set Grid 3 List";
41+
ButtonFour.Command = new Command(() =>
42+
{
43+
SetThreeGrid();
44+
});
45+
46+
var collection = new ObservableCollection<Issue13437Model>();
47+
48+
for (int i = 0; i < 42; i++)
49+
{
50+
collection.Add(new Issue13437Model { Text = "Label " + i.ToString() });
51+
}
52+
53+
Collection.ItemsSource = collection;
54+
55+
BindingContext = new ViewModel10482();
56+
#endif
57+
}
58+
59+
protected override void Init()
60+
{
61+
62+
}
63+
#if APP
64+
void SetVerticalList()
65+
{
66+
Collection.ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical);
67+
}
68+
69+
void SetHorizontalList()
70+
{
71+
Collection.ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal);
72+
}
73+
74+
void SetTwoGrid()
75+
{
76+
Collection.ItemsLayout = new GridItemsLayout(ItemsLayoutOrientation.Vertical)
77+
{
78+
Span = 2,
79+
HorizontalItemSpacing = 5,
80+
VerticalItemSpacing = 5
81+
};
82+
}
83+
84+
void SetThreeGrid()
85+
{
86+
Collection.ItemsLayout = new GridItemsLayout(3, ItemsLayoutOrientation.Vertical);
87+
}
88+
#endif
89+
}
90+
91+
public class Issue13437Model
92+
{
93+
public string Text { get; set; }
94+
}
95+
}

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewGroupTypeIssue.cs" />
1313
<Compile Include="$(MSBuildThisFileDirectory)Issue11214.cs" />
1414
<Compile Include="$(MSBuildThisFileDirectory)Issue13109.cs" />
15+
<Compile Include="$(MSBuildThisFileDirectory)Issue13437.xaml.cs">
16+
<DependentUpon>Issue13437.xaml</DependentUpon>
17+
</Compile>
1518
<Compile Include="$(MSBuildThisFileDirectory)Issue13126.cs" />
1619
<Compile Include="$(MSBuildThisFileDirectory)Issue13126_2.cs" />
1720
<Compile Include="$(MSBuildThisFileDirectory)Issue13551.cs" />
@@ -2665,6 +2668,10 @@
26652668
</EmbeddedResource>
26662669
</ItemGroup>
26672670
<ItemGroup>
2671+
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue13437.xaml">
2672+
<SubType>Designer</SubType>
2673+
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
2674+
</EmbeddedResource>
26682675
<EmbeddedResource Include="$(MSBuildThisFileDirectory)VisualGallery.xaml">
26692676
<SubType>Designer</SubType>
26702677
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>

Xamarin.Forms.Platform.UAP/CollectionView/FormsGridView.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ void FindItemsWrapGrid()
7878

7979
_wrapGrid.SizeChanged -= WrapGridSizeChanged;
8080
_wrapGrid.SizeChanged += WrapGridSizeChanged;
81+
82+
UpdateItemSize();
8183
}
8284

8385
void WrapGridSizeChanged(object sender, SizeChangedEventArgs e)

Xamarin.Forms.Platform.UAP/CollectionView/ItemsViewRenderer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ protected virtual void UpdateItemsLayout()
418418

419419
SetNativeControl(ListViewBase);
420420

421+
_defaultHorizontalScrollVisibility = null;
422+
_defaultVerticalScrollVisibility = null;
423+
421424
UpdateItemTemplate();
422425
UpdateItemsSource();
423426
UpdateVerticalScrollBarVisibility();

0 commit comments

Comments
 (0)