0
votes

I'm trying to create a ListView with Xamarin Forms. The RowHeight for each of the list element may very dynamically when it is populated.

Please let me know how we can set the RowHeight of the list item dynamically.

var StatusList = new ListView
        {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
            RowHeight = Constants.CategoryRowHeight + 60,
            BackgroundColor = Constants.BackgroundColor,
            ItemTemplate = GetDataTemplate()
        };
2

2 Answers

1
votes

You can set the HasUnevenRows property of ListView to True.

    var StatusList = new ListView
    {
        HorizontalOptions = LayoutOptions.FillAndExpand,
        VerticalOptions = LayoutOptions.FillAndExpand,
        HasUnevenRows = true,
        RowHeight = Constants.CategoryRowHeight + 60,
        BackgroundColor = Constants.BackgroundColor,
        ItemTemplate = GetDataTemplate()
    };
1
votes

There is a bug on iOS which causes that the rows cannot have different heights. Setting HasUnevenRows=true only causes that you can set a custom height for ALL cells. If this bug ever gets fixes, I can inform you. But: this will work for UWP and Android, so you can use a different CellView for iOS instead