0

The code works as expected in Android but in iOS works inconsistently. The selected label's border changes colour when tapped, sometimes. After 3 or four taps of different labels they cease to be selected at all. Long pressing a label works as expected, opening a different view. On returning to the view containing the CollectionView code attached, label selection has been re-enabled. The process then repeats itself. I've tried changing Nuget versions of both Xamarin.Forms and Xamarin.Community.Toolkit(even the latest pre-release), xaml and code-behind to no avail. I'm at a loss. Any help would be appreciated.

<CollectionView x:Name="categoryCollectionView"
                                ItemsSource="{Binding Categories,Mode=TwoWay}"
                                SelectionMode="Single"
                                SelectedItem="{Binding Category}"
                                SelectionChanged="OnMenuItemSelected"
                                Grid.Column="0"
                                HorizontalOptions="FillAndExpand"
                                Grid.ColumnSpan="8" 
                                Grid.Row="3"
                                VerticalScrollBarVisibility="Always" >
                <CollectionView.ItemsLayout>
                    <GridItemsLayout x:Name="CategoriesGridLayout"
                                     Orientation="Vertical" 
                                     Span="3"
                                     VerticalItemSpacing="2"/>
                </CollectionView.ItemsLayout>
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Grid  Padding="0">

                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="Selected">
                                        <VisualState.Setters>
                                            <Setter TargetName="lblCategory" Property="Label.TextColor" Value="Red" />
                                            <Setter Property="BackgroundColor" Value="Green" />
                                        </VisualState.Setters>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>

                            <StackLayout  Orientation="Vertical" 
                                          VerticalOptions="Center"
xct:TouchEffect.LongPressCommand="{Binding LongPressCategoryCommand, Source={RelativeSource AncestorType={x:Type vm:CategoryVM}}}"
                                          xct:TouchEffect.LongPressCommandParameter="{Binding CategoryString}" >
                                <StackLayout.Margin>
                                    <OnPlatform x:TypeArguments="Thickness" iOS="2,2,4,4" Android="2" />
                                </StackLayout.Margin>

                                <Label  x:Name="lblCategory"
                                        Text="{Binding CategoryString}"
                                        FontSize="Small"
                                        BackgroundColor="#f5e2e1"
                                        VerticalOptions="Center"
                                        HorizontalOptions="CenterAndExpand"
                                        WidthRequest="350"
                                        Padding="5"
                                        TextColor="#232F34"
                                        LineBreakMode="TailTruncation"
                                        Style="{DynamicResource CategoryLabelStyle}" >
                                    <Label.Triggers>
                                        <DataTrigger TargetType="Label"
                                                         Binding="{Binding Source={x:Reference fontSizeSwitch}, Path=IsToggled}"
                                                         Value="true">
                                            <Setter Property="FontSize"
                                                          Value="Medium" />
                                            <Setter Property="Padding"
                                                          Value="2" />
                                        </DataTrigger>
                                    </Label.Triggers>
                                </Label>

                            </StackLayout>
                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>

  • Sorry,I can't fully understand what you mean. Can you please send a short video to elaborate on your problem? – Jessie Zhang -MSFT Oct 27 '21 at 06:43
  • Thanks for your interest Jessie. I have a CV of labels. When a label is selected (tapped) the VisualStateManager highlights it with a green border. I'm trying to use the Xamarin Community Toolkits TouchEffect.LongPressCommand on the same labels to trigger an event in the viemodel. As I said, the code works fine on Android but not iOS where a few labels may be highlighted before the code hangs. – fishfinger Oct 30 '21 at 04:13
  • Thanks for your feedback. Could you please post a basic demo to github or onedriver so that we can test on our side? – Jessie Zhang -MSFT Nov 02 '21 at 08:09
  • Normal behaviour with LongPress Disabled: [disabled link](https://drive.google.com/file/d/1PTuuNrbO4yA6hHKlv1Okqok2RxRQNlbB/view?usp=sharing) LongPress Enabled . There is eventually no response to taps but the LongPress opens another view, as expected. [enabled link](https://drive.google.com/file/d/1teSjidrhZoBkzPGkSNg9kq_KtCx7ASB8/view?usp=sharing) – fishfinger Nov 05 '21 at 01:23

0 Answers0