Forum Xamarin.Forms

Go to end of Listview after loading from database

I have a Listview with a ViewCell that i fill with data from Firebase database.

But how do i go to the end of the list after loading the data ?

Now i have to scroll to the end and when the list is long that is not nice to do.

`

                    <ListView.ItemTemplate>

                        <DataTemplate>
                            <ViewCell Height="70"    >
                                <ContentView Padding="20,0,20,0">

                                    <StackLayout Spacing="0">
                                        <Label Text="{Binding Wie}" TextColor="Gray" FontSize="Micro" HorizontalOptions="StartAndExpand" HeightRequest="20" />
                                        <Label Text="{Binding Name}" TextColor="Black" FontSize="Small" HorizontalOptions="StartAndExpand" LineBreakMode="WordWrap"
                           MaxLines="10"/>
                                    </StackLayout>
                                </ContentView>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>`
Tagged:

Best Answer

Answers

  • BorisopritBorisoprit Member ✭✭✭

    Here is how i get the data with a Class FirebaseHelper

    Loading in Xaml.cs

    ` protected async override void OnAppearing()
    {

            base.OnAppearing();
            var allPersons = await firebaseHelper.GetAllPersons();
            lstPersons.ItemsSource = allPersons;
    
    
    
        }`
    

    And in public class FirebaseHelper

    ` public async Task<List> GetAllPersons()
    {

            return (await firebase
             .Child("Persons")
             .OnceAsync<Person>()).Select(item => new Person
    
            {
                 Name = item.Object.Name,
                  Wie = item.Object.Wie,
                 Wanneer = item.Object.Wanneer,
    
        }).ToList();
    
    
        }`
    
  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    I think you can remove the animation when you use ScrollTo
  • BorisopritBorisoprit Member ✭✭✭

    What do you mean AlessandroCaliaro

  • BorisopritBorisoprit Member ✭✭✭

    Thanks LandLu ,

    That is working fine.

Sign In or Register to comment.