Search code examples
c#xamarin.formsxamarin.forms.carouselview

Carouselview not scrolling to set position


I have a carouselview that renders well, but when i change the position property of it programmatically, it does not scroll to the position. Moreover, when i add a breakpoint to it and check to see at which position my carousel is, the position value sits correctly at the predefined position until i reach that position. After that, it follows the position of the caruselview. This is the xaml code:

    <CarouselView ItemsSource="{Binding FilteredLocations}"
              Position="{Binding Position}"
              EmptyView="No items to display.">

This is the C# part that controls the position: private int position;

    public int Position
    {
        get => position;
        set
        {
           SetProperty(ref position, value);
        }
    }

    public void SelectLocation(Location loc)
    {
        int i = 0;
        var comparer = EqualityComparer<Location>.Default;
        foreach (Location l in FilteredLocations)
        {
            if (comparer.Equals(l, loc))
            {
                Position = i;
            }
            i++;
        }
    }

Anybody that knows how to fix this issue?


Solution

  • So, the solution was to update Xamarin forms to 5.0. The carouselview seems to be quite buggy in 4.8