Skip to content

Carousel control crashes on addition without initial items #905

Closed
@SamirKharchi

Description

@SamirKharchi

Describe the bug
The carousel control crashes when it has no items initially and one adds items afterwards.

To Reproduce

  1. Add a carousel without any initial items
  2. Add an item (e.g. via code) once the view has been initialised.
  3. Crashes with an Out-of-bounds exception

Expected behavior
No crash.

Additional context
Debugging shows that Carousel.UpdateItemsPosition() is crashing once it tries to use the PageIndex, which is -1 at that point and therefore of course out-of-bounds.

Possible fix is to update the PageIndex to an in-bounds range value when an item is added.

private void UpdateItemsPosition()
{
    if (!CheckNull() || !_appliedTemplate || Items.Count == 0)
        return;

    if (PageIndex == -1) // Fixes the crash
    {
         PageIndex = 0;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions