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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

I need to get the currentItem from the controls inside the itemTemplate

Thread ID:

Created:

Updated:

Platform:

Replies:

149660 Dec 4,2019 04:20 PM UTC Dec 9,2019 04:54 PM UTC Xamarin.Forms 5
loading
Tags: SfListView
Victor Rafael Bocanegra Arias
Asked On December 4, 2019 04:20 PM UTC

Good morning, I have an SfListView with controls defined for each record within ItemTemplate and I would like to be able to obtain the currentItem when each control is accessed within the template, for possible validations. This is possible?

Gnana Priya Namasivayam [Syncfusion]
Replied On December 5, 2019 12:27 PM UTC

Hi Victor, 
 
Thank you for using Syncfusion product. 
 
We would like to inform that you can CurrentItem of SfListview through the commands/events like ItemTapped, ItemDoubleTapped,SelectionChanged, SelectionChanging etc., like below. We have attached the code snippet and documentation for your reference, please find it from below. 
 
 
 
 
 
 
public class Behavior : Behavior<SfListView> 
{ 
    SfListView Listview; 
    protected override void OnAttachedTo(SfListView bindable) 
    { 
       Listview = bindable; 
       Listview.ItemTapped += Listview_ItemTapped; 
 
       base.OnAttachedTo(bindable); 
    } 
         
    private void Listview_ItemTapped(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e) 
    { 
       var listview = sender as SfListView; 
       var currentItem = listview.CurrentItem as BookInfo; 
       if (currentItem == null) 
          return; 
       App.Current.MainPage.DisplayAlert("Message", "CurrentItem of listview: " + currentItem.BookName, "Ok"); 
    } 
} 
 
 
Please let us know if you need any further assistance. 
 
Regards, 
Gnana Priya N 


Victor Rafael Bocanegra Arias
Replied On December 5, 2019 07:05 PM UTC

Thank you for the prompt response, it does work, but it has a problem. Within the ItemTemplate of the SfListView I have three controls: CheckBox, Entry and SfNumericTextBox, when I tap on one of them, the event does not trigger me. This is normal? Any chance so that when you tap the control it extends to its predecessor?

Gnana Priya Namasivayam [Syncfusion]
Replied On December 6, 2019 11:38 AM UTC

Hi Victor, 
 
We would like to inform that when you tap interactable control loaded inside the ItemTemplate, touch will pass only to the respective child control. Here, touch will pass to parent only when tapped on any layouts other than controls inside the ItemTemplate. This is the actual behavior.  
 
Meanwhile, we suggest you to hook to the respected control’s tap/any interaction event in order to get the BindingContext (Model class) of that control through which you can get the binded model data. 
 
Regards, 
Gnana Priya N 


Victor Rafael Bocanegra Arias
Replied On December 6, 2019 12:17 PM UTC

Thank you for the excellent response, I don't know if you could help me with an example please! XD

Gnana Priya Namasivayam [Syncfusion]
Replied On December 9, 2019 04:54 PM UTC

Hi Victor,  
 
We have prepared the sample in which we have displayed a previous item’s binding context value for Entry and Button like below. We have attached the tested sample for your reference, please find the sample from below. 
 
 
 
public partial class MainPage : ContentPage 
{ 
        BookInfo previousBtnItem=null, previousEntryItem=null,currentEntryItem,currentButtonItem; 
        public MainPage() 
        { 
            InitializeComponent(); 
        } 
 
        private void Entry_Focused(object sender, FocusEventArgs e) 
        { 
            var bcEntry = (sender as Entry).BindingContext as BookInfo; 
 
            currentEntryItem = bcEntry; 
 
            if (previousEntryItem!=null) 
            { 
                DisplayAlert("Message", "Previous entry item " + previousEntryItem.BookName, "Ok"); 
 
            } 
             previousEntryItem= currentEntryItem; 
 
        } 
 
        private void Button_Clicked(object sender, EventArgs e) 
        { 
            var bcButton = (sender as Button).BindingContext as BookInfo; 
            currentButtonItem = bcButton; 
 
            if (previousBtnItem != null) 
            { 
                DisplayAlert("Message", "Previous entry item " + previousBtnItem.BookName, "Ok"); 
 
            } 
            previousBtnItem= currentButtonItem; 
 
        } 
} 
 
 
Please let us know if you need any further assistance. 
 
Regards, 
Gnana Priya N 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon