xamarin.forms - 使用 xamarin.forms 未完全加载 ListView 项目
问题描述
我的列表视图控制器不会加载所有元素,在这种情况下它只会加载 1 个元素,在其他情况下它会像 4 一样加载,但其他的则不会
当我测试问题发生的位置时,我知道问题出在 Frame 控制器上,这要归功于我的 List View 上的大多数项目都没有加载的框架
<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>
我提到的结果是我的项目加载不完整,如下图所示:
[已编辑] 我已将代码编辑如下,但错误仍然相同
<ListView
SeparatorVisibility="None"
IsGroupingEnabled="True"
ItemsSource="{Binding TasksCollection}"
GroupDisplayBinding="{Binding Key}"
HasUnevenRows="True">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<TextCell
Text="{Binding Key}"
TextColor="White"/>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame
HeightRequest="150"
Margin="10"
HasShadow="True"
CornerRadius="25"
BackgroundColor="White">
<Grid
Padding="5">
<Grid.GestureRecognizers>
<TapGestureRecognizer Command="{Binding GridExpandCommand}"/>
</Grid.GestureRecognizers>
<Grid.RowDefinitions>
<RowDefinition Height="2*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label
Grid.Column="0"
Grid.Row="0"
Text="{Binding Name}"
FontAttributes="Bold"
FontSize="Small"
HorizontalOptions="Start"
VerticalOptions="Start">
</Label>
<Image
HeightRequest="25"
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="Small"
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>
</ListView>
解决方案
仅当您的布局不适合时才会发生这种情况(除了您发送可能会看到的空数据的小问题),您试图将太大的项目放入太小的空间中。您应该设置图像的HeightRequest
和WidthRequest
,并且可能还需要设置LineBreakMode
标签。
推荐阅读
- c++ - 带有 spotify/json 的枚举字段的编解码器
- android - “此应用无权使用 Firebase 身份验证”
- node.js - 指定客户端端口Node js请求
- android - 从后台调用 REST API 时 UI 冻结?
- javascript - 如何在 React-Native 或 JavaScript 中实现 Shopify - 客户登录?
- python-3.x - 使用 cv2 和 numpy 的奇数图像
- ruby-on-rails - 保存记录时忽略Rails Form Timezone
- mysql - 删除具有两个或多个条件的重复标题的行
- javascript - 用户值在 jQuery 的警报功能之前是准确的,但 saveorupdate 函数将空值保留在 db 表中
- mariadb - mariadb 中的 Fetch Check 约束定义