I change a RadListView's SelectedItem programmatically. When I do, I need RadListView to scroll to the new SelectedItem. This thread discusses the issue: https://www.telerik.com/forums/implementing-scroll-to-item
My Solution has both Android and iOS projects. I'm starting with iOS by implementing the class shown below. The code does not crash, but neither does it work. Any hints or ideas you have would be most welcome. I also need to get this working on Android.
Thanks in advance for your help.
P.S. My initial impression is that this scrolling should be included out-of-the-box. Please consider this an enhancement request.
public class RadListViewRenderer : Telerik.XamarinForms.DataControlsRenderer.iOS.ListViewRenderer
{
private RadListView listView = null;
private NSIndexPath indexPath;
protected override void OnElementChanged(ElementChangedEventArgs<RadListView> e)
{
base.OnElementChanged(e);
listView = e.NewElement;
if (listView != null)
{
listView.SelectionChanged += selectionChanged;
}
}
private void selectionChanged(object sender, NotifyCollectionChangedEventArgs args)
{
if (args.NewItems?.Count > 0 && listView != null)
{
int index = (int)listView.ItemsSource.GetType().GetMethod("IndexOf").Invoke(listView.ItemsSource, new[] {args.NewItems[0]});
indexPath = NSIndexPath.FromItemSection(index, 0);
Control.ScrollToItem(indexPath, UICollectionViewScrollPosition.Top, false);
}
}
}