Xamarin Forms Carousel does not update view since xamarin forms 5.0.0.2291

Eric 1 Reputation point
2022-04-19T10:00:32.27+00:00

Hi everybody
Xamarin Adroid:
I have a carousel showing pictures. When i add pictures Itemsource is updated (observablecollection).
With Xamarin forms 5.0.0.224 nuget package everything works fine but since 5.0.0.2291 refresh is not correct. issue is the same with the last 5.0.02401.
Sometimes nothing is drawn, sometimes only few items are drawns (not the complete collection). When i debug, i see that collection applied on itemsource is good, it seems to be a drawing problem

If someone on the developpement team can take a look about this issue, it could be great. Thanks

Now i use android 12 SDK and target 12, but it is the same with android 11. issue is not device dependant (android 9 to 12).

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,326 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Eric 1 Reputation point
    2022-04-22T14:41:04.39+00:00

    Hi,
    I have made a new simpliest project and i have same behavior.

    In the view a simple carousel with label:

    <ContentPage.Resources>
        <ResourceDictionary>
             <DataTemplate x:Key="PostItemTemplate">
        <Grid  x:Name="GridGlob" BackgroundColor="Green" Margin="5">
                     <Label Grid.Row="1" Text="{Binding .}" />
                </Grid>
    </DataTemplate>
        </ResourceDictionary>
    </ContentPage.Resources>
    

    <CarouselView BackgroundColor="Pink" ItemTemplate="{DynamicResource PostItemTemplate}"
    x:Name="carou" Loop="False" ItemsSource="{Binding LesItems}" PeekAreaInsets="50">

    in the viewmodel

        private ObservableCollection<string> _LesItems;
        public ObservableCollection<string> LesItems
        {
            get { return _LesItems; }
            set { _LesItems = value;
                OnPropertyChanged();
            }
        }
    

    Now just add a button in the view with command binding viewmodel doing this:

          ObservableCollection<string> obsCol = new ObservableCollection<string>();
            obsCol.Add("ble");
            obsCol.Add("sdf");
            obsCol.Add("erz");
            obsCol.Add("grz");
            obsCol.Add("efs");
            obsCol.Add("new");
            LesItems = obsCol;
    

    since Xamarin forms 5.0.0.2291:
    First time, everything is good, 6 items are drawn . If you clic again , You will see only 4 items and most of time only 1 item (debug show that "LesItems" contains 6 items but only 1 is drawn)

    With old Xamarin forms 5.0.0.224:
    It always works fine. No matter number of clic. all items are drawn that should be normal behaviour because each time you clic it must replace collection by nex one and drawing all items.

    Thanks for your help