The solution in my case was to put the ListView
inside a StackLayout
and then put that StackLayout
inside the main StackLayout
. Then I could set the VerticalOptions = LayoutOptions.FillAndExpand
on the inner StackLayout
(the one containing the ListView
) with the result that the ListView
got the space it needed (which of course varies depending on the data).
Here is the main code:
listView.ItemsSource = alternativeCells;
listView.ItemSelected += ListViewOnItemSelected;
var listStackLayout = new StackLayout
{
VerticalOptions = LayoutOptions.FillAndExpand,
Orientation = StackOrientation.Vertical
};
listStackLayout.Children.Add(listView);
_stackLayout.Children.Add(listStackLayout);
As you see, I added a new StackLayout
with the only purpose of putting the ListView
inside it. Then I put that listStackLayout
inside the main _stackLayout
.
See the post on this Xamarin forum post for more information
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…