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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Getting the index of the presented item

Thread ID:

Created:

Updated:

Platform:

Replies:

143411 Mar 19,2019 02:34 PM UTC Mar 25,2019 12:48 PM UTC Xamarin.Forms 5
loading
Tags: SfCarousel
Alessandro Del Sole
Asked On March 19, 2019 02:34 PM UTC

Hello,
is there a way to retrieve the index of the item that is currently presented in the SfCarousel control? My need would basically be to select an item at swipe, and the SelectionChanged event is not useful, as it is raised only when an item is actually tapped.

Thanks in advance,
Alessandro

Mugundhan Saravanan [Syncfusion]
Replied On March 20, 2019 01:19 PM UTC

Hi Alessandro Del Sole 
 
We have checked the reported issue "Getting the index of the presented item" and we suggest to use SelectedIndex property to retrieve the index of the selected item. 
We have provided the sample for your reference below. 
 
 
Thanks.
Mugundhan S.
 


Alessandro Del Sole
Replied On March 20, 2019 01:51 PM UTC

Thank you very much for your kind reply and example.

I forgot to mention I would need this to work with the Linear view mode of the Carousel, and this example won't work because the events SelectionChanged and PropertyChanged for SelectedIndex will not be fired until an item is tapped.

I would be happy to get the same result with a horizontal SfListView, by the way. 

Thanks again!

Mugundhan Saravanan [Syncfusion]
Replied On March 21, 2019 12:55 PM UTC

Hi Alessandro Del Sole,

Thanks for your update.

We have checked the reported issue by changing the ViewMode property to Linear in the sample. The behaviour as such, the PropertyChanged for SelectedIndex when the ViewMode is linear and the SelectionChanged event will be fired only when the item is tapped. We recommend you to use the Default ViewMode in order to retrieve the SelectedIndex without tapping.

Please let us know if you have any other concern.

Regards,
Mugundhan S.

Alessandro Del Sole
Replied On March 21, 2019 01:57 PM UTC

I have solved using a SfListView with horizontal orientation, then retrieving the index via the ScrollRows property of the VisualContainer object in the ScrollStateChanged event as follows:

            if (e.ScrollState == ScrollState.Idle || e.ScrollState == ScrollState.Fling)
            {
                var lineIndex = visualContainer.ScrollRows.GetVisibleLineAtPoint(300);
            
Not an elegant solution, but in this case I can predict the point in which a list item becomes visible at scrolling.

Dhanasekar R [Syncfusion]
Replied On March 25, 2019 12:48 PM UTC

Hi Alessandro, 
 
Thanks for the update.  In order to get the Visible items from list view, we recommend you to use DisplayItems property. And then you can get the index from Display items. 
 
Code snippet
 
var items = listView.DataSource.DisplayItems;
List<int> visibleIndex = new List<int>();
for (int i = 0; i < items.Count; i++)
{
    visibleIndex.Add(listView.DataSource.Items.IndexOf(items[i]));
} 
 
Regards, 
Dhanasekar 


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

;