I'm pretty new to Xamarin so I may be missing something simple, but I cannot for the life of me get a layout going in a ListView which can dynamically adjust the vertical height of the element when some bound elements are missing.
Here's the XAML...
<ContentPage.Content>
<StackLayout>
<ListView ItemsSource="{Binding Items}" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="0">
<Grid.RowDefinitions>
<RowDefinition Height="22"></RowDefinition>
<RowDefinition Height="{Binding PriceHeight}"></RowDefinition>
<RowDefinition Height="{Binding ShortDescriptionHeight}"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="80"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding Everything}" Font="Large" LineBreakMode="TailTruncation" />
<Label Grid.Row="1" Grid.Column="0" Text="{Binding Price}" IsVisible="{Binding HasPrice}" Font="Large" />
<Label Grid.Row="2" Grid.Column="0" Text="{Binding ShortDescription}" IsVisible="{Binding HasShortDescription}" Font="Medium" TextColor="Gray" LineBreakMode="WordWrap" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage.Content>
When PriceHeight = 0
and HasPrice = False
and ShortDescriptionHeight = 0
and HasShortDescription = False
I'm getting exactly what I expect. My list item is short and just displays the data from Everything
. But if PriceHeight = 0
and HasPrice = False
and ShortDescriptionHeight = 10
and HasShortDescription = True
... it allocates a big glob of empty whitespace for row 1 between Everything
and ShortDescription
.
I'm clearly missing something. Who can help me with what that something is?