Search code examples
c#androidsqlitexamarin.formsxamarin.forms.listview

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


I have recently noticed a problem with my listview and my local database using sqlite and Xamarin.Forms, my problem is that when the data of my table is dumped into my ObservableCollection (source item of the ListView) and my List View shows it, the ListView does not shows all the items in that are being supposed to be shown, i have tried by adding dynamically (without a database) items into my List View and by this way the problem seems to disappear, i am sure that the problem is not from my sqlite database beacuse also the problem in one past project that i use an api for getting my info the problem was the same, so i got in the conclusion that the problem was showing external information into my ListView so does anyone knows a possible solution for my problem, by the other way, it would be really helpful if someone could try doing a project with listview and sqlite database.

Important fact: The ListView in my XAML has the Frame controller, so when I don't use it, it shows me all the items from the database, I also don't know why

my current XAML code:

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

My code for adding the items into the collection (I use MvvmHelpers for grouping the data with Grouping) is the following:

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 result is the following:

The image of the result of the app

Any answer i will be noticed about it, and also for any question, it would be awesome some help please!


Solution

  • I have finally solved it, and as i expected was a bug of my current version of Xamarin.Forms (4.0.0) so i update to the newest version of it and everything returns ok, as i expected!