Display Swipe Template programmaticaly or on item tap/click ?

Hello,

Is there a way to programmaticaly swipe left/right on sflistview items ?
Or a way to swipe left or right just by tapping the item ?

Thanks,
Sylvain

5 Replies

JN Jayaleshwari N Syncfusion Team August 31, 2018 09:29 AM UTC

Hi Sylvain,    
    
Thanks for using Syncfusion Products.    
    
We have checked the reported query “Want to swipe listview item programmatically” from our end. We would like to know that we have achieved your requirement in our sample. As of now we don’t have direct support to swipe an item programmatically, so we handled swipe manually by passing InitialPosition to ProcessTouchMove method. Here, we have passed 0th  children in our sample, you can pass any item in the list by passing items index. We have attached the sample for your reference, please let us know whether the sample meets your requirement.    
    
You can download the sample from below link.    
    
    
    private void button_Clicked(object sender, EventArgs e)    
        {    
            var btn = sender as Button;    
            Device.BeginInvokeOnMainThread(async () =>    
           {    
               VisualContainer visualContainer = listView.GetVisualContainer();    
               int count = visualContainer.Children.Count();    
               Random r = new Random();    
               int index = r.Next(0, count);    
               var swipeController = listView.GetType().GetRuntimeProperties().FirstOrDefault(ptyname => ptyname.Name == "SwipeController").GetValue(listView);    
               var item = visualContainer.Children[0];    
               if (item is SwipeView)    
                   return;    
               var swipeItem = item.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name =="ListViewItemInfo").GetValue(item);    
               if (swipeItem == null)    
                   return;    
               var iteminfo = swipeItem as ListViewItemInfoBase;    
               var position = iteminfo.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name =="InitialPosition");    
               position.SetValue(iteminfo, 10);    
               var swipeStarted = swipeController.GetType().GetRuntimeMethods().FirstOrDefault(methd => methd.Name == "ProcessTouchMove");    
               swipeStarted.Invoke(swipeController, new object[] { iteminfo, new Point(120, 10) });    
               await Task.Delay(1000);    
           });    
        }    
    
            //You can call this method to reset the swiped item     
            //listView.ResetSwipe();       
    
    
You can also reset swiped item by calling ResetSwipe method.    
    
Please let us know if you require any further assistance.    
    
Regards,    
Jayaleshwari N. 



MO Morten July 10, 2019 09:00 PM UTC

How do I modify this sample to open the right swipe template? I can only get it to open the left swipe template.


DB Dinesh Babu Yadav Syncfusion Team July 11, 2019 08:33 AM UTC

Hi Morten, 
 
You can achieve the reported requirement by using the width of the listview and passing it through swipe methods accordingly as like below code example, 
 
Code Example [C#]: 
private void Rightbutton_Clicked(object sender, EventArgs e) 
{ 
   Device.BeginInvokeOnMainThread(async () => 
   { 
     VisualContainer visualContainer = listView.GetVisualContainer(); 
     int count = visualContainer.Children.Count(); 
     var width = visualContainer.Bounds.Width; 
     Random r = new Random(); 
     int index = r.Next(0, count); 
     var swipeController = listView.GetType().GetRuntimeProperties().FirstOrDefault(ptyname => ptyname.Name == "SwipeController").GetValue(listView); 
     var item = visualContainer.Children[0]; 
     if (item is SwipeView) 
         return; 
     var swipeItem = item.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "ListViewItemInfo").GetValue(item); 
     if (swipeItem == null) 
         return; 
     var iteminfo = swipeItem as ListViewItemInfoBase; 
     var position = iteminfo.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "InitialPosition"); 
      position.SetValue(iteminfo, width - 10); 
     var swipeStarted = swipeController.GetType().GetRuntimeMethods().FirstOrDefault(methd => methd.Name == "ProcessTouchMove"); 
     swipeStarted.Invoke(swipeController, new object[] { iteminfo, new Point(width - 160, 0) }); 
     await Task.Delay(1000); 
   }); 
 
   //You can call this method to reset the swiped item  
   //listView.ResetSwipe(); 
} 
 
For your reference, we have prepared the sample with above code example and you can download it from the below link. 
 
 
Please let us know if you require further assistance. 
 
Regards, 
Dinesh Babu Yadav 



MO Morten July 11, 2019 12:15 PM UTC

Thanks for the sample. I really appreciate it!

There is however a problem where when you use this code to programmatically swipe an item, then the user can't swipe any other item until they've manually closed the swipe menu of the programmatically swiped item, where as normally the previously swiped item would automatically reset when tapping on another item or swiping another item.

The problem seems to get fixed by having the user tap once on the programmatically swiped item, which visually does nothing as the item is still swiped, but after that the user can tap on another item or swipe another item as normally to collapse the previously swiped item.

Is it possible modify the sample to fix this issue or somehow combine the sample with an automatic programmatic tap on the item that was programmatically swiped, to make everything function as normal again for the user?


DB Dinesh Babu Yadav Syncfusion Team July 12, 2019 10:19 AM UTC

Hi Morten, 
 
As per your requirement, we have prepared the sample with Swiping scenario and you can download it from the below link. 
 
 
Please let us know, if you need further assistance on this. 
 
Regards, 
Dinesh Babu Yadav 
 


Loader.
Up arrow icon