Bug 57876 - ViewCell containing ListView crashes on orientation change
Summary: ViewCell containing ListView crashes on orientation change
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.4
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Jimmy [MSFT]
Depends on:
Reported: 2017-06-30 10:33 UTC by Chad Magendanz
Modified: 2017-07-05 16:03 UTC (History)
2 users (show)

Tags: android listview tableview viewcell
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Chad Magendanz 2017-06-30 10:33:52 UTC
When a ViewCell contains a ListView, for example in a hamburger menu which contains a list of recent projects as well as other menu commands, changing orientation will results in an unhanded exception.

To repo:
- Create new project in VS2017 using Cross Platform App (Xamarin) template
- Select Blank App and Shared Project
- In MainPage.xaml, substitute the following Content:

      <TableSection Title="User">
        <ImageCell ImageSource="Icon.png" Text="UserName" Detail="Email" />
      <TableSection Title="Recent Projects">
          <ListView />

Build and run Android project, then change orientation on device or emulator.

Result: Exception Unhandled (no call stack or exception details available because app is in break mode)

Populating ListView contents through binding in XAML or in codebehind doesn't seem to make a difference.
Comment 1 Jimmy [MSFT] 2017-07-05 16:03:12 UTC
I am seeing a crash at launch on Android when using the provided XAML, whether there are items or not in the ListView: https://gist.github.com/jimmgarrido/77d5beee5242a7bb2586cfbc95e758f5

Even though this appears to work on iOS and UWP, having a ListView inside a ViewCell is not something we recommend or support so you may encounter further issues by doing this.

I would suggest using a ListView and DataTemplateSelector[1] instead of a TableView. This way you can use a single ListView and still be able to provide a the list of recent items. Another approach might be to use a layout like StackLayout. When using this approach, avoid using a ScrollView if possible as there can be issues when using a ListView inside a ScrollView.

Hope this helps!