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

[UWP] Fix issue changing the ItemsLayout in CollectionView #13470

Merged
merged 2 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<controls:TestContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="Xamarin.Forms.Controls.Issues.Issue13437"
Title="Issue 13437">
<ContentPage.Content>
<StackLayout>
<Label
Padding="12"
BackgroundColor="Black"
TextColor="White"
Text="Tap each Button to change the CollectionView ItemsLayout. If in all cases, the ItemsLayout changes correctly, the test has passed."/>
<Button x:Name="ButtonOne"/>
<Button x:Name="ButtonTwo"/>
<Button x:Name="ButtonThree"/>
<Button x:Name="ButtonFour"/>
<CollectionView
x:Name="Collection"
ItemsSource="{Binding Items}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Label
Text="{Binding Text}"
WidthRequest="100"/>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</ContentPage.Content>
</controls:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System.Collections.Generic;
using Xamarin.Forms.CustomAttributes;
using System.Collections.ObjectModel;

#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Issue(IssueTracker.Github, 13437, "[Bug] Changing ItemsLayout of CollectionView at runtime does not work on UWP",
PlatformAffected.UWP)]
public partial class Issue13437 : TestContentPage
{
public Issue13437()
{
#if APP
InitializeComponent();

ButtonOne.Text = "Set Vertical List";
ButtonOne.Command = new Command(() =>
{
SetVerticalList();
});

ButtonTwo.Text = "Set Horizontal List";
ButtonTwo.Command = new Command(() =>
{
SetHorizontalList();
});

ButtonThree.Text = "Set Grid 2 List";
ButtonThree.Command = new Command(() =>
{
SetTwoGrid();
});

ButtonFour.Text = "Set Grid 3 List";
ButtonFour.Command = new Command(() =>
{
SetThreeGrid();
});

var collection = new ObservableCollection<Issue13437Model>();

for (int i = 0; i < 42; i++)
{
collection.Add(new Issue13437Model { Text = "Label " + i.ToString() });
}

Collection.ItemsSource = collection;

BindingContext = new ViewModel10482();
#endif
}

protected override void Init()
{

}
#if APP
void SetVerticalList()
{
Collection.ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Vertical);
}

void SetHorizontalList()
{
Collection.ItemsLayout = new LinearItemsLayout(ItemsLayoutOrientation.Horizontal);
}

void SetTwoGrid()
{
Collection.ItemsLayout = new GridItemsLayout(ItemsLayoutOrientation.Vertical)
{
Span = 2,
HorizontalItemSpacing = 5,
VerticalItemSpacing = 5
};
}

void SetThreeGrid()
{
Collection.ItemsLayout = new GridItemsLayout(3, ItemsLayoutOrientation.Vertical);
}
#endif
}

public class Issue13437Model
{
public string Text { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
<Compile Include="$(MSBuildThisFileDirectory)CollectionViewGroupTypeIssue.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11214.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13109.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13437.xaml.cs">
<DependentUpon>Issue13437.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)RadioButtonTemplateFromStyle.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShellWithCustomRendererDisabledAnimations.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ShellFlyoutContent.cs" />
Expand Down Expand Up @@ -2634,4 +2637,10 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue13437.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions Xamarin.Forms.Platform.UAP/CollectionView/FormsGridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ void FindItemsWrapGrid()

_wrapGrid.SizeChanged -= WrapGridSizeChanged;
_wrapGrid.SizeChanged += WrapGridSizeChanged;

UpdateItemSize();
}

void WrapGridSizeChanged(object sender, SizeChangedEventArgs e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ protected virtual void UpdateItemsLayout()

SetNativeControl(ListViewBase);

_defaultHorizontalScrollVisibility = null;
_defaultVerticalScrollVisibility = null;

UpdateItemTemplate();
UpdateItemsSource();
UpdateVerticalScrollBarVisibility();
Expand Down