我的列表视图对象接收图像,ID号和概要。概要的大小不同,因为有些人有空白回报。我注意到ListView有一个我可以设置的行高(我现在设置为250),但它只能是一个固定值。所以会发生什么,我的网格对于ListView来说变得太高了,导致它溢出并覆盖到下一个列出的项目上。无论如何在XAML中自动调整列表视图的大小?
<ListView ItemsSource="{Binding List}" VerticalOptions="FillAndExpand" RowHeight="250" SelectedItem="SelectedCTR" SeparatorVisibility="None">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.Row="0" HeightRequest="100" MinimumWidthRequest="160" WidthRequest="160" Source="{Binding AttachedmentData,Converter={StaticResource stringToImage}}" />
<StackLayout Grid.Row="1" VerticalOptions="FillAndExpand">
<Label Text="{Binding Number}" Font="19"
TextColor="#f35e20" />
<Label Text="{Binding TrimmedSynopsis}" Font="17"
TextColor="#503026" />
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
答案 0 :(得分:6)
您需要将
HasUnevenRows
添加到 True ,然后取消设置RowHeight
属性。
<ListView ItemsSource="{Binding List}" VerticalOptions="FillAndExpand" HasUnevenRows="True" SelectedItem="SelectedCTR" SeparatorVisibility="None">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.Row="0" HeightRequest="100" MinimumWidthRequest="160" WidthRequest="160" Source="{Binding AttachedmentData,Converter={StaticResource stringToImage}}" />
<StackLayout Grid.Row="1" VerticalOptions="FillAndExpand">
<Label Text="{Binding Number}" Font="19"
TextColor="#f35e20" />
<Label Text="{Binding TrimmedSynopsis}" Font="17"
TextColor="#503026" />
</StackLayout>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
答案 1 :(得分:0)
答案 2 :(得分:0)
仅设置Listview属性HasUnevenRows =“ True”