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

问题描述 投票:0回答:1

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

重要事实:我的XAML中的ListView具有Frame控制器,因此当我不使用它时,它将向我显示数据库中的所有项目,我也不知道为什么] >

我当前的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

任何答案我都会被注意到,对于任何问题,请提供一些帮助!

我最近注意到我的列表视图和使用sqlite和Xamarin.Forms的本地数据库存在问题,我的问题是,当我将表的数据转储到我的ObservableCollection中(源...

c# android sqlite xamarin.forms xamarin.forms.listview
1个回答
0
投票
我终于解决了它,并且正如我所期望的那样,是我当前版本的Xamarin.Forms(4.0.0)的一个错误,因此我将其更新到最新版本,并且一切都按我的预期返回了!
© www.soinside.com 2019 - 2024. All rights reserved.