Hello,
I have a listview that contains messages, I want to scroll down the list to the last message when I open the page.
Hello,
I have a listview that contains messages, I want to scroll down the list to the last message when I open the page.
Hello,
Welcome to our Microsoft Q&A platform!
I want to scroll down the list to the last message when I open the page.
ListView provides the ScrollTo method will could help you scroll the ListView to the item.
Check the code:
<ListView x:Name="listView" ItemsSource="{Binding DataCollection}">
...
</ListView>
public partial class TestPage : ContentPage
{
TestPageViewModel viewModel;
public TestPage()
{
InitializeComponent();
viewModel = new TestPageViewModel();
BindingContext = viewModel;
}
protected override void OnAppearing()
{
base.OnAppearing();
listView.ScrollTo(viewModel.DataCollection[viewModel.DataCollection.Count-1], ScrollToPosition.End, true);
}
}
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
It Works like this too
if (MessagesListView.ItemsSource != null)
{
var lastItem = MessagesListView.ItemsSource.Cast<object>().LastOrDefault();
MessagesListView.ScrollTo(lastItem, ScrollToPosition.End, true);
}
7 people are following this question.