Hi,
With v28.1.39 my ItemsSource is an ObservableCollection that can be refreshed with different items depending of the user choices.
On iOS the first initialization of the collection works, but the second time, whenever I use new ObservableCollection<Item>(); or the .Clear(); method it throws an ArgumentOutOfRangeException.
The 28.1.35 release notes says : Addressed an exception that occurred when dynamically clearing the SfCarousel ItemsSource collection on the iOS platform.
If I rollback to 28.1.36 or 28.1.35 I still have the exception.
Regards,
Julien
Hi Julien,
We have reviewed your query and created a sample based on your update. However, we were unable to reproduce the reported issue. The ItemSource collection of the SfCarousel was refreshed successfully without any exceptions. Additionally, we tested the scenario with an empty collection, and it worked as expected.
To better assist you, could you please provide us with the complete code or a sample demonstrating the issue with replication steps would be extremely helpful. This will enable us to thoroughly investigate and propose a more accurate solution.
For your convenience, we have included the tested sample and a demonstration video as an attachment. Please review the attached files and let us know if you have any concerns. If necessary, please make any required modifications and share the updated sample with us.
Please don’t hesitate to contact us if you have any queries.
Regards,
Aarthi A.
Hi,
Your sample allowed me to identify precisely where the issue is.
In fact it is the SfCarousel.SelectionChanged event that is too often triggered on iOS comparing to Android.
My code for this event is something like this :
if (sender is Syncfusion.Maui.Carousel.SfCarousel sfCarousel) { |
On iOS this event is triggered even when the ItemsSource is cleared, but not on Android. So the ElementAt method throws the exception on iOS because the ItemsSource is empty.
I have updated your sample if you want to check.
Now it's easy to fix on my side, but maybe you can improve things to get the same behavior on Android and iOS.
Regards,
Julien
Hi Julien Barach,
Thank you for bringing this to our attention and providing the details of the behavior you observed.
We have reviewed the issue you mentioned regarding the SfCarousel.SelectionChanged event being triggered more frequently on iOS compared to Android, particularly when the ItemsSource is cleared. As you noted, this discrepancy can lead to exceptions being thrown on iOS when attempting to retrieve an item from an empty ItemsSource.
To address this, we have made a modification to the sample code to ensure the ItemsSource count is checked before accessing the selected item.
|
if (sender is Syncfusion.Maui.Carousel.SfCarousel sfCarousel && sfCarousel.ItemsSource != null) { var source = sfCarousel.ItemsSource as IList<Item>; if (source?.Count > sfCarousel.SelectedIndex) { var selectedItem = sfCarousel.ItemsSource.ElementAt(sfCarousel.SelectedIndex) as Item; } } |
This ensures that the code gracefully handles cases where the ItemsSource is empty, preventing exceptions on iOS.
Additionally, we have taken your suggestion into consideration to align the behavior of the SelectionChanged event across both Android and iOS platforms. Our team will explore improvements to achieve consistent functionality across devices. Once these enhancements are implemented, we will notify you or share the details with you.
We have also attached the updated sample for your reference. Please check it and let us know if it resolves the issue on your end.
Regards,
Kamalesh P