Retrieving the parent ViewCell of the selected item in the SfListView

Hi,
I have a SfListView with a DataTemplate that contains a ViewCell and nested views. The SfListView provides me the CurrentItem property that returns the selected data object, but is it possible to retrieve the instance of the containing ViewCell? This is because I need to interact with controls in the data template at runtime, not just the data bound object.

With Xamarin's ListView, I can do this by simply catching the Tapped event on the ViewCell. Unfortunately, this doesn't work with the SfListView and ViewCell's Tapped event is ignored/not fired.

Any help would be appreciated. Thanks in advance.

1 Reply

MK Muthu Kumaran Gnanavinayagam Syncfusion Team February 23, 2018 01:08 PM UTC

Hi Alessandro, 
 
We have checked your requirement from our side. We would like to let you know that you can achieve your requirement by extending a Grid element inside the ItemTemplate of SfListView and using TapGestureRecognizer you can get the elements inside them as like below. 
 
Code Example[C#]: 
public partial class GroupingPage : ContentPage 
    { 
        public GroupingPage() 
        { 
            InitializeComponent(); 
        } 
    } 
 
    public class GridExt : Grid 
    { 
        public GridExt() 
        { 
            var gesture = new TapGestureRecognizer(); 
            gesture.Tapped += Gesture_Tapped; 
            this.GestureRecognizers.Add(gesture); 
        } 
 
        private void Gesture_Tapped(object sender, EventArgs e) 
        { 
           //Your code here. 
        } 
    } 
 
Code Example[XAML]: 
<?xml version="1.0" encoding="utf-8" ?> 
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:local="clr-namespace:Grouping;assembly=Grouping" 
             xmlns:listView="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms" 
             xmlns:dataSource="clr-namespace:Syncfusion.DataSource;assembly=Syncfusion.DataSource.Portable" 
             x:Class="Grouping.GroupingPage"> 
   
  <ContentPage.BindingContext> 
    <local:ContactsViewModel /> 
  </ContentPage.BindingContext> 
  <ContentPage.Content> 
      <listView:SfListView x:Name="listView" ItemSize="70" ItemsSource="{Binding contactsinfo}" > 
 
        <listView:SfListView.ItemTemplate> 
          <DataTemplate> 
            <ViewCell> 
                <local:GridExt x:Name="grid" RowSpacing="1"> 
                  . 
                  . 
                  . 
                </local:GridExt> 
            </ViewCell> 
          </DataTemplate> 
        </listView:SfListView.ItemTemplate> 
      </listView:SfListView> 
  </ContentPage.Content> 
</ContentPage> 
 
For your assistance, we have attached the sample and you can download it from the below link. 
 
 
Please let us know if you require further assistance. 
 
Regards, 
G.Muthu kumaran. 


Loader.
Up arrow icon