Bug 40764 - Xamarin.Forms.ListView fails to layout correctly in case of variable Height row content
Summary: Xamarin.Forms.ListView fails to layout correctly in case of variable Height r...
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.2.0
Hardware: All Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL: https://github.com/neurospeech/listvi...
Depends on:
Reported: 2016-04-28 18:09 UTC by Akash Kava
Modified: 2017-01-07 00:53 UTC (History)
4 users (show)

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 Akash Kava 2016-04-28 18:09:20 UTC
# Steps to reproduce
1. Create a MasterDetailPage with two pages
2. Create a project with ListView and ViewCell as a template
3. Create a list of models, each model has a property as ItemHeight, which returns 20, if we tap the item, ItemHeight should toggle between 20 and 40, so assume that we want to show selected item as a bigger item. ( I know I can use ItemTemplateSelector, but this is not the point).
4. Create Grid inside ViewCell, bind Height of Grid to ItemHeight and setup a Gesture to toggle ItemHeight property

# Expected behavior
1. Height of item should toggle between 20,40
2. When we change between pages of MasterDetailPage, height should retain

# Actual behavior
1. Height does not change after tapping
2. If you change the pages between MasterDetailPage, you can see that Height of item you tapped is now reflecting correctly

# Conclusion
When the page is reloaded after we switch pages between master detail page, height of item changes correctly and we see expected height, but it does not reflect immediately. I tried to find exact class where this bug must be appearing, but it seems that ViewCell's ForceLayout or some method does not cause table to recalculate size of height required. However, on full layout pass, it does work correctly.
Comment 1 Chris King 2016-04-28 19:26:47 UTC
Can you please attach a reproduction project instead of a description? That helps us triage issues much faster as well as ensuring we're constructing the same test case as you're envisioning. 

Warm regards,
Comment 2 Akash Kava 2016-04-29 09:00:00 UTC
Here is sample project in Github,


in same repository, there is iOSBug.mp4 video which demonstrates that height of row does not change, however, it does change in android instantly.
Comment 3 Akash Kava 2016-05-15 10:31:47 UTC
I have added the github repo, to reproduce the bug. Also there is a video explaining the bug.
Comment 5 Samantha Houts [MSFT] 2016-05-27 02:02:48 UTC
@Akash: Thank you for the detailed report!

For performance reasons, we do not automatically resize ListView rows for you. You will need to call ForceUpdateSize on the ViewCell to get your desired behavior. 

Please see https://developer.xamarin.com/samples/xamarin-forms/UserInterface/ListView/DynamicUnevenListCells/ for a detailed example.

Thanks again!!
Comment 6 Akash Kava 2016-05-30 09:45:01 UTC

Your sample does not work in some cases,

We have a ViewModel which requests web service and on response, some UI elements become visible and some change, we have no way to update View from ViewModel without having to do some complex extra code, which still does not work.

This is bad design, you can create a ViewCell which will force automatic resize if we need, I tried to Create new type of ViewCell, but calling ForceSizeUpdate in OnChildMeasureInvalidated does no effect, the bug exists in the software.
Comment 7 Chris King 2017-01-07 00:43:16 UTC
Akash, we've yet to conceive of an efficient, general, and automatic way to detect when to call ForceUpdateSize. So, unfortunately, we pass the buck to the application to decide when a forced update is necessary. The application has more context and yet, as you've discovered, even the non-general case is challenging. Until such time that a general solution can be devised and the non-general case is still to challenging to solve we suggest the application be restructured to use rows of immutable height.

Warm regards,