Xamarin.forms: [CollectionView] Updating the ItemsLayout type should refresh the layout

Created on 23 Feb 2019  路  2Comments  路  Source: xamarin/Xamarin.Forms

More a work task than a bug due to the ongoing development of CollectionView (but we'll just categorize it as a bug for now), it should update its layout when switching the ItemsLayout types from a ListItemsLayout to GridItemsLayout. A good example of where this would be used is in a UI where the user is allowed to toggle between those layouts, such as in a retail app.

This is supposedly semi-functional on iOS but wasn't personally tried. Android doesn't update the layout.

Steps to Reproduce

  1. Use a CollectionView with one of the two layout types
  2. Switch to the other layout type in app (such as via a button tap)

Expected Behavior

The CollectionView updates its layout to the new type.

Actual Behavior

The CollectionView does not update its layout until leaving and reentering the page (such as with tabs).

collectionview blocker 4 bug

Most helpful comment

Another possible usage is to switch the number of columns when the device is rotated.. Much needed.

//Not updating at runtime on Android public void SetColumns(int columns = 2) { var grid = ItemsLayout as GridItemsLayout; if (grid!=null) { if (grid.Span == columns) return; //avoid unneeded } ItemsLayout = new GridItemsLayout(columns, ItemsLayoutOrientation.Vertical); }

All 2 comments

Another possible usage is to switch the number of columns when the device is rotated.. Much needed.

//Not updating at runtime on Android public void SetColumns(int columns = 2) { var grid = ItemsLayout as GridItemsLayout; if (grid!=null) { if (grid.Span == columns) return; //avoid unneeded } ItemsLayout = new GridItemsLayout(columns, ItemsLayoutOrientation.Vertical); }

Is it not possible to have this for UWP also?

Was this page helpful?
0 / 5 - 0 ratings