xamarin-forms-carouselview
xamarin-forms-carouselview copied to clipboard
Android: Suddenly the SelecteIndex Property binding didn't work.
Hi, thank you very much for creating that control!
At the Android CarouselLayoutRenderer.updateSelectedIndex() function, you need to ensure that the carouselLayout.SelectedIndex Property should be set at the UI Thread. Otherwise all of a sudden the PropertyBinding didn't work anymore. I update it like this:
` private void updateSelectedIndex() { var center = _scrollView.ScrollX + (_scrollView.Width / 2); var carouselLayout = (CarouselLayout)Element; var calculatedIdx = (center / _scrollView.Width);
using (var h = new Handler(Looper.MainLooper))
{
h.Post(() => carouselLayout.SelectedIndex = calculatedIdx);
}
}
` Hope that helps someone.
@soernt - thanks for that suggestion!