c# - Xamarin.Forms ListView 在集合更改之前滚动后在 Android 中呈现错误
问题描述
如果我只是在不滚动的情况下修改 ListView 的数据,一切都会正确显示:
https://gfycat.com/illustriousnastyconey
但是,如果我在更改数据之前滚动,则在数据更改后一切看起来都坏了:
https://gfycat.com/abandonedvelvetyaudad
这是我的 ListView XAML
<ListView ItemsSource="{Binding network.Predictions}" x:Name="ShowsList" IsGroupingEnabled="True" HasUnevenRows="True" ItemTapped="ShowsList_ItemTapped">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell Height="25">
<Grid BackgroundColor="#CC778899">
<Label Text="{Binding Category}" FontSize="Small" TextColor="White" VerticalOptions="Center" Margin="5,0,0,0"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid BackgroundColor="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Text="{Binding Name}" FontSize="Medium" Margin="5"/>
<Label Grid.Column="1" Text="{Binding Status}" FontSize="Small" TextColor="{Binding StatusIndex, Converter={StaticResource StatusColor}}" Margin="5" VerticalOptions="Center/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
此外,在发生这种情况之后,如果我滚动以使混乱的元素离开屏幕,然后再滚动回来,这些元素看起来就好了。它似乎确实正确地分配了空间,并且它们在滚动后正确显示,因此它没有错误地读取数据或类似的东西,它只是没有正确显示。
我有一个想法并将列表视图的背景颜色更改为红色,以查看文本是否呈现为白色,但不,那些缺失的元素是完全透明的。正确的元素都有背景色,但缺失的元素只显示为红色。
解决方案
好像是listview的bug,3.6的初始版本就有这个问题,3.6.0.344457已经修复了,很多开发者都遇到过这个问题,如果你有类似的问题,看看:<a href="https ://github.com/xamarin/Xamarin.Forms/pull/6390" rel="nofollow noreferrer">https://github.com/xamarin/Xamarin.Forms/pull/6390 和最快最简单的解决方法它正在滚动 Xamarin.Forms 版本
推荐阅读
- node.js - 如何使用 Nodejs (API) 获取 S3 中的所有图像。我没有钥匙
- c# - 如何在客户端从 C# 调用 c++ .dll?
- node.js - 如何使用 Axios 包向 MailChimp api 发出 post 请求
- postgresql - aws rds postgres9.6:在数据库恢复地理位置列后返回字符串而不是对象
- javascript - 以 JS 为前端的 WebApi 2,如何保护未授权用户的页面?
- python - 从 Csv 文件中获取数组以绘制图表
- ios - 为什么当我输入 tableView.tableHeaderView = searchController.searchBar 行时我的代码会崩溃?
- asp.net-core - Identity Server 4 作为 Angular SPA 的 Web API
- python - 在 MySQL 中将文件内容作为表插入
- php - Laravel 5.8 Passport “导致 `401 Unauthorized`”