ListView 项目未完全从 SQLite 数据库加载 [Xamarin.Forms]

ListView items not completely loading from SQLite database [Xamarin.Forms]

我最近注意到我的列表视图和我使用 sqlite 和 Xamarin.Forms 的本地数据库存在问题,我的问题是当我的 table 的数据被转储到我的 ObservableCollection(源项目ListView) 和我的列表视图显示它,ListView 没有显示应该显示的所有项目,我尝试通过动态添加(没有数据库)项目到我的列表视图中,这样问题似乎消失,我确信问题不是来自我的 sqlite 数据库,因为在过去的一个项目中我使用 api 来获取我的信息也是这个问题,问题是一样的,所以我得出的结论是问题是在我的 ListView 中显示外部信息所以有人知道我的问题的可能解决方案吗,换句话说,如果有人可以尝试使用 listview 和 sqlite 数据库做一个项目,那将非常有帮助。

重要事实:我的 XAML 中的 ListViewFrame 控制器,所以当我不使用它时,它显示了数据库中的所有项目,我也不知道为什么

我当前的XAML代码:

      <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>

我将项目添加到集合中的代码(我使用 MvvmHelpers 通过分组对数据进行分组)如下:

foreach (var item in new string[]
            { Languages.HightPriorText, Languages.MediumPriorText, Languages.LessPriorityText })
            {
                var sorted = from tasks in tableList
                             orderby tasks.PriorityLevel // orberby is a keyword of System.Linq namespace
                             group tasks by tasks.PriorityLevel into taskList
                             select new Grouping<string, TaskItemViewModel>(taskList.Key, taskList);
                List<Grouping<string, TaskItemViewModel>> listItems = sorted.Where(t => t.Key == item).ToList();
                foreach (var item2 in listItems)
                    VeryImportantList.Add(item2);
            }

结果如下:

The image of the result of the app

我会注意到任何答案,还有任何问题,请提供帮助!

我终于解决了它,正如我所料,这是我当前版本 Xamarin.Forms (4.0.0) 的一个错误,所以我更新到它的最新版本和所有内容 returns 好的,如我所料!