I have a Listview in a Grid on a page. The Listview is bound to a Datasource in a ViewModel.
Whenever I add a new item at the end of the to the list I want to scroll it into view. How can this be achived?
I have tried to scroll to the end of the Listview with the with the ScrollTo function using ItemSize multiplied with number of items as a position but this does not work. It scrolls nearly to the end but the last item is always hidden.
I have observed this behavior on the Windows platform.
If we think of it a little bit more general, the question is: What is the recommended way to scroll an item into view?
I have added a Solution with a sample implementation. It adds a new item every two seconds and I want to see the item that was added latest at the bottom of the list without any scrolling.
Hi Frank,
We have checked the reported query “Want to scroll to added item”, you can achieve your requirement by scrolling the newly added item , you can get the notification in the DataSource CollectionChanged , when the new items added or removed to the collection. We have created a sample based on your requirement, attached the sample and code snippet for your reference.
Code snippet:
list.DataSource.SourceCollectionChanged += DataSource_SourceCollectionChanged;
private void DataSource_SourceCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { if(e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add) { list.Dispatcher.Dispatch(() => { list.ItemsLayout.ScrollToRowIndex(e.NewStartingIndex, ScrollToPosition.End, false); }); } } |
As timer is used in the sample , there might be a mismatch in the thread , which leads to the issue , items are scrolled in windows platform ,whereas Dispatch will invokes the ScrollToRowIndex in the main thread.
Also please refer the documentation related to scrolling in SfListView
UG Link: https://help.syncfusion.com/xamarin/listview/scrolling#programmatic-scrolling
Regards,
Suthi Yuvaraj.
Unfortunately this does not scroll down to the last item and makes it visible. The last item is often hidden and you see the last but one item. You can recognize this when you check the scrollbar after an item is added. It is not completely at the end but you can still scroll a little bit down.
We are unable to reproduce the issue at our end ,when adding the new item to the list with Datasource collection changed event ,scrolling works fine. As the DataSourceCollectionChanged Event will get notification for the change in the source collection , you can scroll to the last item using ScrollTo or ScrollToRowIndex. We have attached the tested sample and output video for your reference.
Please modify the sample or share the below details if your still facing the issue which will be more helpful for us to find the solution as soon as possible.
I agree it looks good on the Android platform. In the zip file you can find a video which I recorded on the Windows platform.
Beginning with the 8th element the effect is visible. After the 8th element is added it is not shown completely but only the top of it is visible.
After another item is added the scrollbar is clearly not at the end. A mouse click on the scrollbar always shows one more element.
We are able to reproduce the issue at our end. We have logged a bug report for the reported issue “Want to scroll to added item ". We will fix the issue and include the fix in our weekly nuget which will be rolled out on November 29,2022. We will let you know once it is released with the fix. You can also track the status of the report from the below link.
Feedback link: https://www.syncfusion.com/feedback/38955/windowsprogrammatic-scrolling-doesnot-works-properly-when-adding-the-items-to-the
Disclaimer: Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.
We would like to let you know that , we have tested the reported scenario in source level , we are able the reproduce the same Framework level also , we have used the Framework scrollview and exdented its functionalities in SfListView source, so issue in framework scrollview will affects the listview scrollview. We are trying to fix this issue in source level , we will let you know once you we have fixed the issue. we have logged this issue is logged as bug in framework level.
Please refer to the framework issue report for more reference,
Bug report: https://github.com/dotnet/maui/issues/11526
We have fixed the reported issue “Want to scroll to added item” and included the issue fix in our latest NuGet release update version 20.4.0.51 which is available for download (https://www.nuget.org/). We thank you for your support and appreciate your patience in waiting for this update. Please get in touch with us if you require any further assistance.