我想使用Xamarin数据绑定维护一个完全声明性的UI。
我遵循了这个线程,这是一场噩梦,结局不佳。 https://forums.xamarin.com/discussion/19874/listview-inside-stacklayout-a-height-problem/p2
他们从本质上解决了这个问题,尝试根据内容动态调整列表视图的大小(看起来很脆弱):Xamarin.Forms ListView size to content?
使用此代码,我的列表视图在实际内容之后会产生一堆空白。完全失控。是的,我尝试了HasUnevenRows =“ true”
<ScrollView>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row ="0" Grid.Column="0" Text="Category: " />
<Label Grid.Row ="1" Grid.Column="0" Text="Meal Time: " />
<Label Grid.Row ="0" Grid.Column="1" Text="{Binding Recipe.Category}" />
<Label Grid.Row ="1" Grid.Column="1" Text="{Binding Recipe.MealTime}" />
</Grid>
<ListView VerticalOptions="Start" Grid.Row="1" HasUnevenRows="False" x:Name="IngredientsListView"
ItemsSource="{Binding Recipe.Ingredients}"
RefreshCommand="{Binding LoadRecipesCommand}"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding }"/>
<Label Grid.Row ="0" Grid.Column="1" FontAttributes="Bold" Text="{Binding Count}" />
<Label Grid.Row ="0" Grid.Column="2" FontAttributes="Bold" Text="{Binding Measure}" />
<Label Grid.Row ="0" Grid.Column="3" FontAttributes="Bold" Text="{Binding Name}" />
<Label Grid.Row ="1" Grid.Column="2" Grid.ColumnSpan="2" FontAttributes="Italic" FontSize="Micro" Text="{Binding Note}" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView VerticalOptions="Start" Grid.Row="2" HasUnevenRows="False" x:Name="InstructionsListView"
ItemsSource="{Binding Recipe.Instructions}"
>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding .}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</ScrollView>