xamarin/Xamarin.Forms
ListView height calculated wrong after setting new ItemsSource
Aperta
#4149 aperta il 19 ott 2018
a/listviewe/5 :clock5:help wantedinactivep/iOS 🍎t/bug :bug:up-for-grabs
Metriche repository
- Star
- (5644 stelle)
- Metriche merge PR
- (Nessuna PR mergiata in 30 g)
Descrizione
Description
Empty ListView or ListView with few items has height calculated incorrectly after swapping ItemsSource if the ListView's available space changes
Steps to Reproduce
This bug happens whenever the ListView is set to a new itemSource after the container's height is recalculated.
- Create a ListView with VerticalOptions = FillAndExpand and a RowHeight
- Make the ListView recalculate its height by any means (adding content, changing text, etc)
- Swap the ListView's itemSource to an empty collection or a collection with not enough items to fill all available height.
Steps 2 and 3 can be swapped in order.
Example:
public class TestPage : ContentPage
{
public Xamarin.Forms.ListView _listView;
public StackLayout _myStack;
public Label _myLabel;
public TestPage()
{
_listView = new ListView //You can set any ItemTemplate you want, it doesn't affect this issue
{
VerticalOptions = LayoutOptions.FillAndExpand,
RowHeight = 230,
IsPullToRefreshEnabled = true,
BackgroundColor = Color.Pink
};
_myLabel = new Label()
{
Text = "test"
};
_myStack = new StackLayout()
{
BackgroundColor = Color.Yellow
};
Content = new StackLayout()
{
Orientation = StackOrientation.Vertical,
VerticalOptions = LayoutOptions.FillAndExpand,
Children =
{
_myStack,
_listView
}
};
}
protected override void OnAppearing()
{
base.OnAppearing();
_listView.ItemsSource = new List<object>();
_myStack.Children.Add(_myLabel);
}
}
Expected Behavior
ListView Vertical FillAndExpand
Actual Behavior
ListView height is set to however many items are in the new itemsSource.
If the itemSource is empty, the ListView will be set to 0 height.
If the itemSource has 1 item, the ListView will be set to the height of 1 item, etc.
Basic Information
- Version with issue: 3.1.0.697729
- Last known good version: Not known
- IDE: Visual Studio 2017
- Platform Target Frameworks:
- iOS:
- Android:
- Android Support Library Version: Android 8.0
- Nuget Packages: Xamarin.Forms
- Affected Devices: All Android and iOS devices