Skip to content

[BUG] Wrong item is registered when pressing an item in a CollectionView using TouchBehavior #1865

@TiicTac54

Description

@TiicTac54

Is there an existing issue for this?

  • I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

Current Behavior

When I press an item in a CollectionView using a TouchBehavior, another item is recorded as pressed.

Screen.Recording.2024-05-08.at.12.00.52.PM.mov

Here's how I configure my TouchBehavior on each element of my list

 <CollectionView Grid.Row="1" ItemsSource="{Binding Items}">
    <CollectionView.ItemsLayout>
        <LinearItemsLayout ItemSpacing="4" Orientation="Vertical" />
    </CollectionView.ItemsLayout>
    <CollectionView.ItemTemplate>
        <DataTemplate>
            <VerticalStackLayout
                Padding="6"
                BackgroundColor="LightGray"
                HeightRequest="50">
                <Label Text="{Binding .}" />
                <VerticalStackLayout.Behaviors>
                    <toolkit:TouchBehavior Command="{Binding Source={x:Reference This},  Path=BindingContext.ItemTapCommandCommand}" CommandParameter="{Binding .}" />
                </VerticalStackLayout.Behaviors>
            </VerticalStackLayout>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>

Expected Behavior

If I press any item in the CollectionView, only the one I press should be registered.

Steps To Reproduce

  1. Have any list with enough items to be able to scroll.
  2. Scroll the list.
  3. Press any items

Link to public reproduction project repository

https://github.com/TiicTac54/TouchBehaviorBugWithCollectionView.git

Environment

- .NET MAUI CommunityToolkit:8.0.x
- OS:Android, iOS
- .NET MAUI:8.0.20

Anything else?

Using a TapGestureRecognizer does not cause this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/behaviorsIssue/Discussion/PR that has to do with BehaviorsbugSomething isn't workingunverified

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions