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

[CollectionView] UWP- Updating the ItemsLayout type should refresh the layout #10316

Closed
wants to merge 11 commits into from
26 changes: 26 additions & 0 deletions Xamarin.Forms.Platform.UAP/CollectionView/ItemsViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE
{
UpdateVerticalScrollBarVisibility();
}
else if (changedProperty.Is(StructuredItemsView.ItemsLayoutProperty))
{
UpdateLayoutManager();
}
else if (changedProperty.IsOneOf(Xamarin.Forms.ItemsView.EmptyViewProperty,
Xamarin.Forms.ItemsView.EmptyViewTemplateProperty))
{
Expand Down Expand Up @@ -157,6 +161,27 @@ void ItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
UpdateEmptyViewVisibility();
}

protected virtual void UpdateLayoutManager()
{
if (Element == null || ListViewBase == null)
{
return;
}


ListViewBase = SelectListViewBase();
ListViewBase.IsSynchronizedWithCurrentItem = false;

SetNativeControl(ListViewBase);

UpdateItemTemplate();
UpdateItemsSource();
UpdateVerticalScrollBarVisibility();
UpdateHorizontalScrollBarVisibility();
UpdateEmptyView();

}

protected virtual void UpdateItemTemplate()
{
if (Element == null || ListViewBase == null)
Expand Down Expand Up @@ -188,6 +213,7 @@ protected virtual void SetUpNewElement(ItemsView newElement)

FindScrollViewer(ListViewBase);

//newElement.PropertyChanged += LayoutPropertyChanged;
Layout.PropertyChanged += LayoutPropertyChanged;

SetNativeControl(ListViewBase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,25 @@ protected override void HandleLayoutPropertyChanged(PropertyChangedEventArgs pro
break;
}
}
else if (property.Is(StructuredItemsView.ItemsLayoutProperty))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the ItemsLayout used, switch between FormsListView and FormsGridView with the appropriate container in ItemsViewRenderer.cs, this block is not necessary.

{
if (ListViewBase is FormsGridView formsGridView)
{
formsGridView.ItemContainerStyle = GetItemContainerStyle((GridItemsLayout)Layout);
}
else
{
switch (ListViewBase)
{
case FormsListView formsListView:
formsListView.ItemContainerStyle = GetVerticalItemContainerStyle((LinearItemsLayout)Layout);
break;
case WListView listView:
listView.ItemContainerStyle = GetHorizontalItemContainerStyle((LinearItemsLayout)Layout);
break;
}
}
}
}

static ListViewBase CreateGridView(GridItemsLayout gridItemsLayout)
Expand Down