Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

ListView in ListView resulting in weird layout and immediate crash when scrolling fast

$
0
0

I have to display a timetable as a list. Therefore I have a ListView for the days, with a template containing another ListView to display all the lessons of a day.
This confronts me with a few problems:

  • The performance is at a great loss because of the many Views, is there another way for me to display each lesson of a day within a single ListView maybe? (I've got LessonDay objects containing the Date as well as a list of all the lessons of that day).

  • Using my approach, the resulting layout adds an extra space at the end of each day and I can't explain why. It looks like this (extra space marked with a red rectangle):

  • Using this layout, if I scroll normally, the app crashes. If I scroll really slowly, however, it doesn't. Hope you can help me out there.

I'm using a XAML ContentPage with the following content:

<StackLayout Padding="10">
    <ListView ItemsSource="{Binding Timetable}" VerticalOptions="FillAndExpand" HasUnevenRows="True">
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <ViewCell.View>
              <StackLayout Orientation="Vertical">
                <Label Text="{Binding Date, StringFormat='{0:dd.MM.yyyy}'}" HorizontalOptions="Center" />
                <ListView ItemsSource="{Binding Lessons}">
                  <ListView.ItemTemplate>
                    <DataTemplate>
                      <ViewCell>
                        <ViewCell.View>
                          <Grid>
                            <Grid.RowDefinitions>
                              <RowDefinition />
                              <RowDefinition />
                            </Grid.RowDefinitions>
                            <StackLayout Orientation="Horizontal">
                              <Label Text="{Binding TimeFrom, StringFormat='{0:hh:mm}'}" />
                              <Label Text="-" />
                              <Label Text="{Binding TimeTo, StringFormat='{0:hh:mm}'}" />
                              <Label Text="{Binding Name}" />
                            </StackLayout>
                            <StackLayout Grid.Row="1" Orientation="Horizontal">
                              <Label Text="{Binding Teacher}" />
                              <Label Text="{Binding Room}" />
                            </StackLayout>
                          </Grid>
                        </ViewCell.View>
                      </ViewCell>
                    </DataTemplate>
                  </ListView.ItemTemplate>
                </ListView>
              </StackLayout>
            </ViewCell.View>
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
  </StackLayout>

Thanks in advance.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>