我的列表视图控制器不会加载所有元素,在这种情况下只加载1个元素,在其他情况下,它会加载4个元素,而其他情况则不加载
[我已经测试了发生问题的位置,所以我知道问题出在框架控制器上,这要归功于框架,我的列表视图上的大多数项目都没有加载
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame
HeightRequest="100"
Margin="10"
HasShadow="True"
CornerRadius="25"
BackgroundColor="White">
<Grid
Padding="5">
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label
Grid.Column="0"
Grid.Row="0"
Text="{Binding Name}"
FontAttributes="Bold"
FontSize="Large"
HorizontalOptions="Start"
VerticalOptions="Start">
</Label>
<Image
HeightRequest="50"
Grid.Row="0"
Grid.Column="1"
Source="{Binding TaskIcon}"
HorizontalOptions="End"
VerticalOptions="Start">
</Image>
<Label
Grid.Row="1"
Grid.Column="0"
Text="{Binding Description}"
FontAttributes="Bold"
FontSize="Medium"
HorizontalOptions="Start"
VerticalOptions="End">
</Label>
<Button
Grid.Row="1"
Grid.Column="1"
Text="{Binding IsDone}"
TextColor="White"
FontAttributes="Bold"
VerticalOptions="CenterAndExpand"
HorizontalOptions="Center"
FontSize="Small"
CornerRadius="100"
BackgroundColor="LawnGreen">
</Button>
</Grid>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
正如我所提到的,结果是我的物品未完全装载,如下图所示:
仅当布局无法容纳(除了琐碎的问题,您正在发送可能会看到的空数据)之外,您正试图将太大的项目容纳在太小的空间中,才会发生这种情况。您应该设置图像的HeightRequest
和WidthRequest
,并且可能还需要为标签设置LineBreakMode
。