This is a migrated thread and some comments may be shown as answers.
Implementing Scroll To Item
2 Answers 33 Views
This is a migrated thread and some comments may be shown as answers.
Duane
Top achievements
Rank 1
Duane asked on 31 Oct 2017, 08:48 PM

I'm trying to create a customrenderer for the ListView control to allow me to scroll to a specific item in list. I've managed to do this for Android, although I had to do reflection to get at the needed properties. But it works well enough.

I'm now trying to implement for iOS and am running into a problem finding the NSIndexPath for the selected item.

I've found the ScrollToItem method on TKListView, but it requires an NSIndexPath. I have access to the actual item from my Xamarin.Forms library, how do I translate that into an NSIndexPath?

2 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 03 Nov 2017, 11:40 AM
Hi, Duane,

You can get the index of the item through the Xamarin.Forms RadListView's ItemsSource in the custom renderer. For example:

protected override void OnElementChanged(ElementChangedEventArgs<RadListView> e)
        {
           base.OnElementChanged(e);
 
           var FormsListView = e.NewElement as RadListView;
           var source = FormsListView.ItemsSource as List<SourceItem>;
           SourceItem item = source.Where(x => x.Name == "Test 1").FirstOrDefault();
           int indexOfItem = source.IndexOf(item);
 
           indexPath = NSIndexPath.FromItemSection(indexOfItem, 0);
        }

Eventually, you can use this indexPath in the ScrollToItem method.

I have attached a sample for your reference.

Regards,
Stefan Nenchev
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Duane
Top achievements
Rank 1
answered on 03 Nov 2017, 03:34 PM
Thanks Stefan, I forgot to come back and post that I figured it out. I went down a similar path, once I realized I could create the NSIndexPath it went quickly. I'll post a blog post on my solution and link it here.
Asked by
Duane
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Duane
Top achievements
Rank 1
Share this question
or