SfListView: Need the event that notifies when the contents of the ItemsSource has changed and the display updated

When we return to a page containing a SfListView the contents of that list has potentially changed so we regenerate the list into the ItemSource and send a PropertyChanged call.

This works as expected and the screen is updated with the new list contents and the scrolling goes to the top of the list.

However, we need to return the scroll position to where it was when the navigation away from the page happened.  We know how to save and restore the position but we have not found a way to be informed when the update has completed.

Mark

6 Replies 1 reply marked as answer

LN Lakshmi Natarajan Syncfusion Team April 5, 2021 11:42 AM UTC

Hi Mark, 
 
Thank you for using Syncfusion products. 
 
We have checked the reported query “Need the event that notifies when the contents of the ItemsSource has changed and the display updated” from our side. We would like to inform you that you can achieve your requirement using the SfListView.PropertyChanged event. Please refer to the following code snippets, 
 
XAML: Hook the PropertyChanged event for the SfListView. 
<syncfusion:SfListView x:Name="listView"  
PropertyChanged="listView_PropertyChanged"                    
ItemsSource="{Binding ContactsInfo}"> 
 
C# 
private void listView_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
{ 
    if(e.PropertyName == "ItemsSource") 
    { 
        //ScrollTo position 
    } 
} 
 
Also, you can refer to our user guidance document to maintain scroll position after updating the ItemsSource from the following link, 
 
Please let us know if you need further assistance. 
 
Regards, 
Lakshmi Natarajan 



MS Mark Sandmann April 5, 2021 06:01 PM UTC

This solution does not work in our application.  I believe that this is because we never reset the ItemSource.  Only the contents of ItemSource.

 I monitored the listView_PropertyChanged  method when I do the update and there were no calls providing a PropertyName of "ItemSource" beyond the instantiation.

After setting the contents I get the following sequence of PropertyNames in the Property Changed method:
"ScrollableContentSize",
 "CurrentItem",
 "SelectedItem",
 "ScrollableContentSize" (9 times)

None of these can ensure that the reload has completed.


SS SaiGanesh Sakthivel Syncfusion Team April 6, 2021 01:43 PM UTC

Hi Mark,

Thank you for the update.

#Regarding Need the event that notifies when the contents of the ItemsSource has changed and the display updated
Currently, we are checking the reported scenario and we will update the further details on or before the April 8 ,2021. We appreciate your patience until then.
 
  
Regards,  
SaiGanesh Sakthivel 



LN Lakshmi Natarajan Syncfusion Team April 9, 2021 03:50 AM UTC

Hi Mark, 
 
Thank you for your patience. 
 
We have checked the reported query “Need the event that notifies when the contents of the ItemsSource has changed and the display updated” from our side. We have attached the tested sample to maintain the scroll position after changing the ItemsSource in the PropertyChanged event.  
 
Please find the sample in the following link, 
 
Also, we would like to inform you that you can get the collection changed notification in the DataSource.DisplayItems.CollectionChanged event.  
 
Please check our sample and let us know if this helps. If not, please modify our sample based on your requirement and revert us back which would be helpful for us to check on it and provide you the solution as soon as possible. 
 
Regards, 
Lakshmi Natarajan 



MS Mark Sandmann April 9, 2021 02:43 PM UTC

My solution is to use the DataSource.DisplayItems.CollectionChanged event as suggested.

The problem with that solution is that we get an event with each item in the list.  Since I know how many items are in the list I wait until the final item's event then set the Scrolling Position.

The one drawback is the user will see a slight flicker as the scrolling goes to the top and then back down to the saved position.  Hopefully they can live with that.


LN Lakshmi Natarajan Syncfusion Team April 12, 2021 11:18 AM UTC

Hi Mark, 
 
Thank you for the update. 
 
We would like to inform you that the DisplayItems.CollectionChanged event with the Reset action will be called only once when updating the existing collection with the new collection. Could you please check our sample and let us know if you still facing the same issue? If not, please modify our sample based on your requirement which would be helpful for us to check on it and provide you the solution as soon as possible. 
 
Meanwhile, you can directly scroll to the previous position in the update collection method itself. Please refer to our online documentation regarding the same from the following link, 
KB links:  
 
Regards, 
Lakshmi Natarajan 


Marked as answer
Loader.
Up arrow icon