CarouselView Position problem

ViikkiViikki USMember ✭✭

I have a CarouselView which is binded to a ObservableCollection. Whenever I add some item in that collection, I set the position of CarouselView to count - 1 of the ObservableCollection, so the view goes to recently added item. It works fine. But if I Clear that observable collection and then I add another item to that collection, the forms app crashes with index out of range. Note that I still didn't set position yet, it just crashes when i add item to the observable collection first time after clearing items. If I never set position of carousel manually, then the code works fine all the time.

is it a bug or i am doing something wrong here?

Posts

  • seanydaseanyda GBMember ✭✭✭✭✭

    Use this CarouselView implementation instead.

    https://github.com/alexrainman/CarouselView

    This is in the process of being merged into Xamarin.Forms and replacing the old CarouselView control, So you may as well use this one now anyway.

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    You're doing something wrong someplace.
    Somewhere you're trying to get element 0 when there aren't any elements.
    Or you're trying to get current - 1 when there is only 1 item (element 0) and thus trying get element number -1 which clearly can't exist.

    Go to your Exception settings and tick on breaking for IndexOutOfRange exception

    Then when you hit it again you should break on the C# line that causes it.
    If it doesn't break on a C# line, then its probably a XAML binding that is failing. For example binding to the last element of the collection - when there is no collection.

  • ViikkiViikki USMember ✭✭

    hello @seanyda, thank you. Replacing the carousel view solved the problem without any other changes.

  • AndreiMisiukevich_AndreiMisiukevich_ USMember ✭✭✭✭✭

    Hi)
    Try this plugin CardsView and CarouselView into single pack!

    nuget.org/packages/CardsView/ -- nuget
    github.com/AndreiMisiukevich/CardView -- source and samples

Sign In or Register to comment.