[Bug] [UWP] Regression bug on CollectionView included in FlyoutPage.Detail
Description
Service Release 9 (5.0.0.2337) introduced a regression that leads to an exception/crash on UWP whenever we revisit a view that contains a CollectionView. We use a FlyoutPage in our mainpage and whenever we present a FlyoutPage.Detail with a CollectionView for the second time, it will crash with a stacktrace containing the lines
System.NotImplementedException: The layout is not implemented
at Xamarin.Forms.Platform.UWP.StructuredItemsViewRenderer`1.SelectListViewBase()
at Xamarin.Forms.Platform.UWP.ItemsViewRenderer`1.SetUpNewElement(ItemsView newElement)
at Xamarin.Forms.Platform.UWP.SelectableItemsViewRenderer`1.SetUpNewElement(ItemsView newElement)
at Xamarin.Forms.Platform.UWP.ItemsViewRenderer`1.OnElementChanged(ElementChangedEventArgs`1 args)
at Xamarin.Forms.Platform.UWP.VisualElementRenderer`2.SetElement
Downgrading to Service Release 8 (5.0.0.2291) eliminates the crash.
We suspect the regression was introduced with PullRequest 14780 since it includes a check for StructuredItemsView
Steps to Reproduce
- Open a Flyout page, containing a CollectionView on UWP
- Navigate to another Detail view
- Revisit the first view
Expected Behavior
FlyoutPage renders the content, including all CollectionViews
Actual Behavior
Crash with "System.NotImplementedException: The layout is not implemented"
Basic Information
- Version with issue: 5.0.0.2337
- Last known good version: 5.0.0.2291
- Platform Target Frameworks:
- UWP: 16299
Reproduction Link
Please see the attached reproduction project UWPCollectionViewNavigationCrash.zip
Workaround
Downgrade to Service Release 8 (5.0.0.2291)
@YZahringer I know it has been a while, but still wanted to ping you to see if you maybe have an idea on this one :)
@jfversluis I think the regression is caused by the ItemsLayout null assignation on https://github.com/xamarin/Xamarin.Forms/pull/14780/files#r734946106.
As commented, I had my doubts in the past about this, but the memory leak persisted otherwise.
A possible way to solve this regression and avoid the memory leak, would be to assign a new LinearItemsLayout or GridItemsLayout instead of null.
So... can this be tested or will we have to remain on the old version forever?
@jfversluis & @YZahringer I'm more than willing to test anything you throw at me. If there is a way to to bundle this change in a NuGet package I'll gladly try it out in our apps.
Any ETA for fix? I am using a workaround of assigning ItemsLayout with a new LinearItemsLayout on revisiting the view.
LinearItemsLayout
@shajiraghav Do you have any example code I could reference for your work around? I'm having this issue in a production project and would like to update to the latest build, but can't because of this issue on UWP
Hello, I am having this issue when the CollectionView when I have the collectionview inside a scroll view.
To make my apps responsive I usually put a ScrollView in my content pages, and put a grid in the scroll view.
Then I use this pattern I picked up somewhere on the internet:
void UpdateLayout()
{
if (width < CUTOFF_WIDTH && height < CUTOFF_HEIGHT)
{
this.Content = scrollView;
scrollView.Content = mainGrid;
SetupScrollingPortraitLayout();
}
else if ( width >= CUTOFF_WIDTH && height < CUTOFF_HEIGHT)
{
this.Content = scrollView;
scrollView.Content = mainGrid;
SetupScrollingLandscapeLayout();
}
else if (width < CUTOFF_WIDTH && height >= CUTOFF_HEIGHT)
{
scrollView.Content = null;
this.Content = mainGrid;
SetupPortraitLayout();
}
else // width >= CUTOFF_WIDTH && height >= CUTOFF_HEIGHT
{
scrollView.Content = null;
this.Content = mainGrid;
SetupLandscapeLayout();
}
}
I call the above in OnSizeAllocated whenever the page size has changed. If I get rid of this craziness and just leave the scroll view at all times, the crash goes away. I just have the scroll view for very small screen sizes like on desktop if the user shrinks the window on a small laptop screen.