Maui: [BUG][Regression][8.0.1] TouchBevavior binding not working in a CollectionView

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

TouchBehavior binding is not working in a CollectionView when using 8.0.1. It seems like the wrong item is binded after the CollectionView is scrolled a bit (recycling issue?). This is a regression in 8.0.1. No issue in 8.0.0.

I mentionned this issue in the PR but so far nobody has reacted. https://github.com/CommunityToolkit/Maui/pull/1791#issuecomment-2039825987

Expected Behavior

I expect it to work the same as in 8.0.0.

Steps To Reproduce

  1. Open and run solution from repro.
  2. Tap on any item. Scroll the CollectionView. Tap again any item.
  3. At some point (probably after recycling of views), the alert shows that the TouchBehavior binds to the wrong item.

untitled.webm

Link to public reproduction project repository

https://github.com/tranb3r/Issues/tree/main/MauiAppMct801TouchBehavior

Environment

- .NET MAUI CommunityToolkit:8.0.1
- OS:Android
- .NET MAUI:8.0.14

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

@phunkeler

This is my current workaround. Just add a TapGestureRecognizer with the command instead of using the TouchBehavior.

                                <!-- There is currently a bug in the touch behavior that causes commands to not be bound correctly in Android. Community Tooklit version 8.0.1 -->
                                <Border.GestureRecognizers>
                                    <TapGestureRecognizer Command="{Binding Command}"/>
                                </Border.GestureRecognizers>
                                <Border.Behaviors>
                                    <mct:TouchBehavior DefaultAnimationDuration="250"
                                                       DefaultAnimationEasing="{x:Static Easing.SpringOut}"
                                                       PressedScale=".95" />
                                </Border.Behaviors>
                                ```

Sure, but this only works for a simple Tap, not for other gestures like LongPress, which is the reason why we’re using TouchBehavior.

We plan on fixing this with a breaking change when we do a major-version bump to .NET 9

Yes, we have a breaking change in our .NET 9 release where we will no longer automatically assign the BindingContext for any CommunityToolkit.Maui.Behavior.