locked
Select-Deselect not working in Xamarin iOS using CollectionView RRS feed

  • Question

  • User394869 posted

    I have a CollectionView in which user can select or deselect multiple names from the ItemSource provided. It is working perfect on Android i.e user can select-deselect multiple names. But in iOS what happens is, if user selects one name and tries to select another name it is not getting selected. But if I scroll a bit and try to select or deselect the name it works. In short when a view is scrolled even if little bit it works fine. User should be able to select or deselect the names without scrolling the view.

    Tuesday, December 29, 2020 8:24 AM

All replies

  • User382871 posted

    But in iOS what happens is, if user selects one name and tries to select another name it is not getting selected. Hi, ukku2215. I tested a basic demo to test the collectionView, the multi selection works fine on both Android and iOS. What the version of Xamarin.Forms and XCode did you test? Try to update them to the lastest stable version and test again.

    If the doesn't work, please post the related code about page and some details about the test environment. It'll help to reproduce the issue to get a solution.


    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    Tuesday, December 29, 2020 2:25 PM
  • User394869 posted

    @Yelinzh am on Xamarin forms version (4.8.0.1364) xcode version 12.0(12A7209)

    Updating to latest versions did not resolve my issue.

    here is my XAML,

    <CollectionView x:Name="NameOfCollectionView" Grid.Row="2" Grid.ColumnSpan="2" HeightRequest="200" ItemsSource="{Binding MyList, Mode=TwoWay}" SelectionMode="Multiple"> <CollectionView.ItemTemplate> <DataTemplate> <Grid Padding="10"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <VisualStateManager.VisualStateGroups> <VisualStateGroup Name="CommonStates"> <VisualState Name="Normal"> <VisualState.Setters> <Setter TargetName="FullName" Property="Label.TextColor" Value="Black" /> </VisualState.Setters> </VisualState> <VisualState Name="Selected"> <VisualState.Setters> <Setter Property="BackgroundColor" Value="#6DB244" /> <Setter TargetName="FullName" Property="Label.TextColor" Value="White" /> </VisualState.Setters> </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Label Grid.Row="0" FontSize="16" x:Name="FullName" Text="{Binding FullName}" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" FontAttributes="Bold"> </Label> </Grid> </DataTemplate> </CollectionView.ItemTemplate> <CollectionView.Behaviors> <behaviors:EventToCommandBehavior EventName="SelectionChanged" Command="{Binding CollectionViewSelectionChangedCommand}" CommandParameter="{x:Reference Page}" /> </CollectionView.Behaviors> </CollectionView>

    Wednesday, December 30, 2020 4:52 AM
  • User382871 posted

    Hi, ukku2215. I tested the posted code on my side, it still works well. Because there is no the code about the 'Behavior' class, I removed the <CollectionView.Behaviors > for test.

    Try to delete the behavior of the collection to test if the project will work.


    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    Wednesday, December 30, 2020 9:38 AM
  • User394869 posted

    @Yelinzh can you post you code that you used after removing the behavior. or you simply removed it and it worked? but that's where my code to select and deselect resides.

    Wednesday, December 30, 2020 9:53 AM
  • User382871 posted

    Here is the related code, you could test it on your side. ```

            <CollectionView  x:Name="NameOfCollectionView"
                 Grid.Row="0"
                 Grid.ColumnSpan="2"
                 HeightRequest="200"
                 SelectionMode="Multiple">
                <CollectionView.ItemsSource>
                    <x:Array Type="{x:Type x:String}">
                        <x:String>mono</x:String>
                        <x:String>monodroid</x:String>
                        <x:String>monotouch</x:String>
                        <x:String>monorail</x:String>
                        <x:String>monodevelop</x:String>
                        <x:String>monotone</x:String>
                        <x:String>monopoly</x:String>
                        <x:String>monomodal</x:String>
                        <x:String>mononucleosis</x:String>
                        <x:String>mononucleosis2</x:String>
                    </x:Array>
                </CollectionView.ItemsSource>
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Grid Padding="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup Name="CommonStates">
                                    <VisualState Name="Normal">
                                        <VisualState.Setters>
                                            <Setter TargetName="FullName" Property="Label.TextColor" Value="Black" />
                                        </VisualState.Setters>
                                    </VisualState>
                                    <VisualState Name="Selected">
                                        <VisualState.Setters>
                                            <Setter Property="BackgroundColor" Value="#6DB244" />
                                            <Setter TargetName="FullName" Property="Label.TextColor" Value="White" />
                                        </VisualState.Setters>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Label Grid.Row="0"
                               FontSize="16"
                               Text="{Binding }"
                               HorizontalOptions="CenterAndExpand"
                               VerticalOptions="CenterAndExpand" FontAttributes="Bold">
                            </Label>
                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </Grid>
    </ContentPage.Content>
    

    ```


    Xamarin forums are migrating to a new home on Microsoft Q&A! We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A! For more information, please refer to this sticky post.

    Wednesday, December 30, 2020 10:08 AM