SfListView swipeitem - get current swiped item Id/Details in ViewModel

I have a simple ListView with two LeftSwipe buttons. 

(1) How can I make the width of each swipe area/label wider? I have tried placing it in grids etc, but the width seems to be fixed. Setting WidthRequest etc does not seem to work.

<syncfusion:SfListView
x:Name="collectionView"
AllowSwiping="True"
AutoFitMode="Height"
BackgroundColor="{StaticResource Gray-100}"
ItemsSource="{Binding ContrastCollection}">
<syncfusion:SfListView.RightSwipeTemplate>
<DataTemplate>

<Grid ColumnSpacing="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
Grid.ColumnDefinitions>

<Label
Grid.Column="0"
BackgroundColor="{StaticResource PrimaryButton}"
FontFamily="FontIcons"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="{StaticResource Edit}"
TextColor="White"
VerticalOptions="Fill"
VerticalTextAlignment="Center">

<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference collectionView}, Path=BindingContext.EditItemCommand}" />
Label.GestureRecognizers>
Label>

<Label
Grid.Column="1"
BackgroundColor="{StaticResource SecondaryButton}"
FontFamily="FontIcons"
HorizontalOptions="Fill"
HorizontalTextAlignment="Center"
Text="{StaticResource Delete}"
TextColor="White"
VerticalOptions="Fill"
VerticalTextAlignment="Center">
<Label.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Source={x:Reference collectionView}, Path=BindingContext.EditItemCommand}" />
Label.GestureRecognizers>
Label>
Grid>
DataTemplate>

syncfusion:SfListView.RightSwipeTemplate>

<syncfusion:SfListView.ItemTemplate>
<DataTemplate>
<StackLayout Spacing="0">
<Label
Padding="12"
FontFamily="Font-Medium"
FontSize="Small"
Text="{Binding Data}" />

<BoxView
BackgroundColor="{StaticResource Gray-300}"
HeightRequest="1" />
StackLayout>
DataTemplate>
syncfusion:SfListView.ItemTemplate>
syncfusion:SfListView>

(2) In the Tapped Event in the TapGestureRecognizer for the Button, how can I get the details of the record that is currently been selected in the Tapped Event?

<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="EditButton_Tapped"/>
Label.GestureRecognizers>

The ItemsSource Model has an Id Field and a Data Field. So ideally in the EditButton_Tapped event, I would need this model for the currently selected item - essentially 'ItemData' but unsure how to get this.


6 Replies 1 reply marked as answer

LN Lakshmi Natarajan Syncfusion Team June 4, 2021 12:14 PM UTC

Hi Reza, 
 
Thank you for using Syncfusion support. 
 
We have checked the reported queries from our side. Please find the details below, 
 
Query 
Response 
(1) How can I make the width of each swipe area/label wider? I have tried placing it in grids etc, but the width seems to be fixed. Setting WidthRequest etc does not seem to work. 
We would like to inform you that you can set the swipe view size by using the SfListView.SwipeOffset property.   
  
Please refer to our user guidance document regarding the same,  
 
(2) In the Tapped Event in the TapGestureRecognizer for the Button, how can I get the details of the record that is currently been selected in the Tapped Event? 
 
The ItemsSource Model has an Id Field and a Data Field. So ideally in the EditButton_Tapped event, I would need this model for the currently selected item - essentially 'ItemData' but unsure how to get this. 
 
We would like to inform you that you can get the swiped item details from the CommandParameter. Please refer to the following code snippets for more reference, 
 
<Label TextColor="Red" BackgroundColor="White"  
Text="Test 4" > 
    <Label.GestureRecognizers> 
       <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" CommandParameter="{Binding .}"/> 
    </Label.GestureRecognizers> 
</Label> 
 
 
 
Please let us know if you need further assistance. 
 
Regards, 
Lakshmi Natarajan 


Marked as answer

AN ANSON March 20, 2022 07:11 AM UTC

I had follow this way ,but still no luck ...any other way 

i just wanna swipe the item and delete it....i using debug and it say my list view is null...i need select n swipe then only can delete 



AN ANSON March 20, 2022 07:18 AM UTC

in xaml i already using command parameter , {binding .}


image_1.png



LN Lakshmi Natarajan Syncfusion Team March 21, 2022 03:10 PM UTC

Hi Anson, 
 
Could you please explain your requirement in detail and share the following details which will be helpful for us to check on it and provide you the prompt solution at the earliest? 
 
  • ListView related code snippets
  • Data population and LeftSwipe_Tapped code snippets
  • Issue replication sample and video
  • Syncfusion and Xamarin.Forms video
 
Regards, 
Lakshmi Natarajan 



HG hoang Gia replied to Lakshmi Natarajan February 14, 2023 10:53 AM UTC

hello

Thank you for this answer on his problem!

May you please provide me an complete example of  this method above

"TapGestureRecognizer_Tapped", I'm currently using a Text Label instead of an Delete Image Icon and also get problem at this step.


Thanks!



RM RiyasHameed MohamedAbdulKhader Syncfusion Team February 15, 2023 12:39 PM UTC

 Hi hoang Gia,

We have attached the sample to obtain the details of a swiped item. Please take a look at the code snippet below for further information.

Code Snippet

private void TapGestureRecognizer_Tapped(object sender, EventArgs e)

{

              var tappedItem = (e as TappedEventArgs).Parameter as ListViewInboxInfo;

              var inboxInfo= (listView.BindingContext as ListViewSwipingViewModel).InboxInfo;

              inboxInfo.Remove(tappedItem);

}


Regards,
Riyas Hameed M


Attachment: ListViewXamarin_6ac28119.zip

Loader.
Up arrow icon