We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Stop swipe menu from collapsing on add and remove of items in the ItemsSource

I'm using an SfListView with an ItemsSource bound to an ObservableCollection of objects, with a swipe menu on every item in the SfListView to display buttons for edit/delete and I've set my ContentPage containing the SfListView up to refresh the data in the ObservableCollection silently when the OnAppearing event gets triggered, but the problem is that if any items get added or removed, the swipe menu will collapse on any of the other items if the user has opened the swipe menu while the data is loading, which disrupts whatever the user was doing.

The swipe menu also collapses when calling OnPropertyChanged on the property used for grouping on the objects in the ItemsSource, regardless of whether any objects have been added or removed from the list.

Is it possible to stop the swipe menu from collapsing when updating the ItemSource of the SfListView in the above scenarios?

5 Replies

DB Dinesh Babu Yadav Syncfusion Team July 8, 2019 09:58 AM UTC

Hi Morten,

Thanks for contacting Syncfusion support.

We have checked with the reported query “SwipeOffset gets reset when updating the cells of the SfListView”. While updating the property of any item in SfListView, the swipe view won’t reset. We have checked the same at our end and it is working as expected. 
 
Also we would like to let you know that the SwipeOffset will be automatically reset when scroll offset or view changed and display items collection changed as like in the following use cases which is intended behavior of SfListView. 
  • While changing the ItemsSource of SfListView.
  • While performing real time operations such as Adding, Removing and Replacing the items of SfListView.
  • When Grouping and Sorting is applied for SfListView items and LiveDataUpdateMode property of SfListView.DataSource is set as ‘LiveDataUpdateMode.AllowDataShaping’.

Please let us know if you require further assistance.

Regards,
Dinesh Babu Yadav




MO Morten July 9, 2019 02:43 PM UTC

Also we would like to let you know that the SwipeOffset will be automatically reset when scroll offset or view changed and display items collection changed as like in the following use cases which is intended behavior of SfListView. 
  • While changing the ItemsSource of SfListView.
  • While performing real time operations such as Adding, Removing and Replacing the items of SfListView.
  • When Grouping and Sorting is applied for SfListView items and LiveDataUpdateMode property of SfListView.DataSource is set as ‘LiveDataUpdateMode.AllowDataShaping’.

---

This is my exact problem. How do I bypass this behavior so that I can add and remove items to an existing ItemsSource, as well as apply Grouping and Sorting with LiveDataUpdateMode enabled without collapsing the swipe menu? I need to be able to refresh the data in the SfListView in the background without the user noticing the refresh and without interrupting their work, which means adding and removing items in the existing ItemsSource, as well as updating the grouping and sorting properties on the objects in the list, without the swipe menu collapsing.



MM Mageshyadav M Syncfusion Team July 10, 2019 05:07 PM UTC

Hi Morten, 
 
We have checked the reported query from our end.  We would like to inform you that we can’t able to bypass this behavior. Because, without refreshing the items we can’t able to perform any real time operations like Add, Remove, Replace, or changing the ItemsSource as well. So, we can’t able to perform without collapsing the swipe menu. 
 
Regards, 
Mageshyadav.M 



MO Morten July 10, 2019 06:43 PM UTC

That is extremely unfortunate as it means I won't be able to refresh the data in the background without disrupting the user when the data is loaded in.

Are there any alternative solutions to this problem? Is there some kind of event I can catch to block the collapse from happening or a way I can programatically swipe the collapsed item back out immediately or something like that?


MM Mageshyadav M Syncfusion Team July 11, 2019 04:45 PM UTC

Hi Morten, 
 
We would like to let you know that we have provided alternate solution for the reported query.  
 
In the SwipeEnded event, we can maintain the ItemData of last swiped item. Also, the swipe offset value has been calculated manually to perform left or right swipe programmatically. 
 
private void ListView_SwipeEnded(object sender, SwipeEndedEventArgs e) 
{ 
   swipedItem = e.ItemData; 
   swipeOffset = listView.SwipeOffset; 
   if (e.SwipeDirection.ToString() == "Left") 
      swipeOffset = swipeOffset * (-1); 
} 
 
Whenever performing the real time operations when the item is not in swipe, we have to skip resetting the maintained swiped item. Hence, set null to the swiped item in SwipeReset event only when no real time operations are performed. 
 
private void ListView_SwipeReset(object sender, ResetSwipeEventArgs e) 
{ 
   if (canReset) 
      swipedItem = null; 
} 
 
So, that we can achieve your requirement using Programmatic Scrolling. Here, we have implemented a demo for adding an item. Similarly, you can achieve it in all the real time applications. 
 
private void Add_Clicked(object sender, EventArgs e) 
{ 
   canReset = false; 
   var contacts = new Contacts(); 
   contacts.ContactName = "DataBase"; 
   contacts.ContactNumber = "192-10000"; 
   (listView.ItemsSource as IList).Insert(1, contacts); 
 
   if (swipedItem != null) 
      listView.SwipeItem(swipedItem, swipeOffset); 
 
   canReset = true; 
} 
We have prepared a sample for your reference. Please download it from the below link. 
 
Regards, 
Mageshyadav.M 


Loader.
Live Chat Icon For mobile
Up arrow icon