locked
My carousel no change of position when i set the value of property from code RRS feed

  • Question

  • User390044 posted

    Im have a carousel (https://github.com/alexrainman/CarouselView) where the user can see samples, these samples are added one by one, and the user could see the last one created each time that he press the button, in android the project works fine, but in iOS the carousel has a very strange behavior, because when user press button add(see below) in the carousel only appears the first and last elements in the item source :S

    I attached some code to understand better this situation.

    xmla page

    <controls:CarouselViewControl x:Name="cvSamplings" ItemsSource="{Binding ListSamplings, Mode=TwoWay}" PositionSelected="cvSamplings_PositionSelected"
                                          Orientation="Horizontal" InterPageSpacing="10" Position="{Binding MyPosition,Mode=TwoWay}"                                        
                                          VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
    

    code to change current position

    var index = viewModel.AddSample();
    BindCarouselView();
    viewModel.MyPosition = index;
    
    Tuesday, December 3, 2019 8:38 PM

All replies

  • User369979 posted

    How do you add views from BindCarouselView(); and what does this index represent for? I created a project based on the sample above. It runs fine on iOS and we could reach the end of the carousel view:

    Wednesday, December 4, 2019 8:03 AM
  • User390044 posted

    @LandLu said: How do you add views from BindCarouselView(); and what does this index represent for? I created a project based on the sample above. It runs fine on iOS and we could reach the end of the carousel view:

    i've attached my project, please could you check my solution? thanks!

    Thursday, December 5, 2019 6:46 PM
  • User369979 posted

    I changed the type of ListSamplings from List to ObservableCollection and then comment out the BindCarouselView method in the btnAdd_Clicked:

    private void btnAdd_Clicked(object sender, EventArgs e)
    {
        var index = viewModel.AddSample();
        //BindCarouselView();
        viewModel.MyPosition = index;
    }
    

    This is becasue ObservableCollection implement the INotifyCollectionChanged interface it could aware of the changing of items. Therefore, we don't need to use BindCarouselView to reset the items source. I attached the modified project here.

    Monday, December 9, 2019 5:39 AM
  • User222383 posted

    I use Xamarin forms version of 4.6.0.1142 and the Carousel View does not react when the position is changed programmatically. But when swiped the contentview is shown up. Any ideas on it , Please help me.

    Thursday, August 13, 2020 3:59 PM
  • User147320 posted

    Any news on this issue? I'm experiencing this also..

    Friday, April 2, 2021 6:41 PM