-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.NET MAUI GestureRecognizers not working on certain controls #8895
Comments
What platform is this? I tested on Windows, Android and iOS and is working as expected the TapGestures is called, the problem is if you add the ta gesture on iOS and Android the Windows - works fine |
Code use to test:
|
@rmarinho If the TapGestureRecognizer blocks the state change of the control, what would be the correct way of attaching a command to the Switch or the Checkbox? |
@otium99 yeah, the team needs to discuss this but we need to add a new api like CheckCommand to th checkbox .. in the meanwhile you should use codebehind and subscribe the event and call your command from there. |
Doesn't work on <ListView.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapGestureRecognizerTapped"
NumberOfTapsRequired="2" />
</ListView.GestureRecognizers> |
Bug: Putting Frame inside ListView's ItemTemplate blocks tap action to trigger on a ListView item. |
Embedding the gesture in a CollectionView also doesn't work.
But take the ContentView outside of the CollectionView and make it the only descendant of a page for example, then it works:
Edit: Nov/17/22: see the comment here |
@BenderNK this is also my experience. Have you discovered any work-around? Thanks! |
Hello @abcox, |
@BenderNK thanks for the feedback. what i am doing for now is using a transparent rectangle |
Command event not working for Span.GestureRecognizers.
|
### Tapped event not working for Span.GestureRecognizers.
|
Not Work Too <CollectionView Grid.Row="2" Grid.ColumnSpan="2"
ItemsSource="{Binding Items}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="{x:Type x:String}">
<SwipeView>
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem Text="Delte"
BackgroundColor="Red"
Command="{Binding Source={RelativeSource AncestorType={x:Type xx:MainViewModel}}, Path=DeleteCommand}"
CommandParameter="{Binding .}"/>
</SwipeItems>
</SwipeView.RightItems>
<Grid Padding="0,5">
<ListView>
<ListView.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={RelativeSource AncestorType={x:Type xx:MainViewModel}}, Path=MMMCommand}"
CommandParameter="{Binding .}"/>
</ListView.GestureRecognizers>
</ListView>
<Frame>
<Label Text="{Binding .}"
FontSize="24"/>
</Frame>
</Grid>
</SwipeView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView> |
No gestures work on the Map control either.
|
Just to add to this issue. I'm seeing the same issue when using Tap Gesture's inside of a Frame that is inside of a CollectionView. XAML <Grid Margin="20">
<ScrollView>
<CollectionView ItemsSource="{Binding TaskList, Mode=TwoWay}">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid HeightRequest="120" Margin="0" Padding="0" RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="8"/>
</Grid.RowDefinitions>
<Frame BackgroundColor="#FAFAFA" CornerRadius="10">
<Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TaskClickedCommand}" CommandParameter="{Binding .}"/>
</Frame.GestureRecognizers>
<StackLayout Orientation="Vertical">
<Label ... />
<Label ... />
<Label ... />
</StackLayout>
</Frame>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</ScrollView>
</Grid> csharp [RelayCommand]
private void TaskClicked(TaskModel task)
{
Console.WriteLine(task.Name);
Console.WriteLine("Task Clicked");
System.Diagnostics.Debug.WriteLine("Task Clicked");
} I'm using the CommunityToolkit.MVVM, in case it's important. I tried it without the top Grid and ScrollView and same results, the command is never called. Edit: I may just be an idiot. I changed: <Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TaskClickedCommand}" CommandParameter="{Binding .}"/>
</Frame.GestureRecognizers> to <Frame.GestureRecognizers>
<TapGestureRecognizer Command="{Binding Path=TaskClickedCommand, Source={RelativeSource AncestorType={x:Type viewModel:HomeViewModel}}}" CommandParameter="{Binding .}"/>
</Frame.GestureRecognizers>
And added <ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:viewModel="clr-namespace:NameRemoved.ViewModel"
x:Class="NameRemoved.View.HomeView"
Title="Home"> |
I have the same need as yours, Span.GestureRecognizers does not work, did you find another solution? |
Is your repo public? Can have a look. Seems to be very hit or miss sadly. |
It is public, and it is a small application for practice. |
Is there any idea when this is going to get looked at or resolved? This is a serious issue which blocks any iOS releases. |
Same issue with the carousel view. I wanted to use the tapGesture instead of custom gestures (I come from Xamarin, and do not want to use the custom renders anymore, which i would need for custom gestures). So for now i hoped i could use the As a workaround I tried to create a custom control for the Image, which has a reference to the viewmodel but for some reason if the Method is called defined in Tested on android, not tested on iOS because i need something that works for both platforms. |
Same here with Image inside a Grid in CollectionView DataTemplate.
|
Same problem in DataTemplate .
|
I have just created a new MAUI app and added a Carousel control. It works absolutely fine until I try adding a tap gesture to it. When I start it the left right scrolling is completely unresponsive in the android phone emulator, but the tap gesture works fine both in code and xml. Can any one tell me if MAUI simply doesn't support adding gestures to some controls? If so shouldn't Microsoft state that in the documentation. Alternatively perhaps the tap gesture overrides the built in left/right scroll of the control. I tried scroll gesture with the same result. I am new to MAUI, so any advice would be appreciated. |
The issue here is about gestures not working. In your case where gestures are working but a control isn't, you should create a new issue. |
I have the same issue. As @Greg-Bates-Trimble said, when the visibility of control(s) (not necessarily the control that has the tap gesture) is changed, gesture stops working. |
Thought to share my workaround on this issue. |
I use the tapgesturerecognizer nested in a collectionview and the command does not execute, if the item is not visible at loading time. |
Why is this issue not getting attention? This seems like a very basic feature that Maui needs to support. I keep on fighting with workarounds for Maui, it's annoying. |
Because unfortunately MAUI doesn’t have nearly enough resource assigned to it at Microsoft. |
This code as a DataTemplate for CollectionView caused items to be invisible. Took some time to find the issue, which is very frustrating. I tried to change the event to command - items are now visible, but the command doesn't fire. Tried switching Border to HorizontalStackLayout, but it has the same issue. I have no workaround. This definitely doesn't get the attention it should be getting! |
@Vroomer I have it working on an image (Android and iOS). This code works for me, note i am on .NET7. Would be helpfull if you add more information about what you are using and for what platform. <CarouselView.ItemTemplate>
<DataTemplate
x:DataType="vme:TestViewModel"
>
<Border
BackgroundColor="Transparent"
Margin="20,0,20,0"
Padding="0,0,0,0"
>
<Grid
Margin="0"
Padding="0"
VerticalOptions="Center"
HorizontalOptions="Center"
>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ActivityIndicator
Grid.Column="0"
Grid.Row="0"
IsRunning="{Binding IsLoading}"
IsVisible="{Binding IsLoading}"
Scale="1.5"
VerticalOptions="Center"
HorizontalOptions="Center"
/>
<Border
Grid.Column="0"
Grid.Row="0"
Margin="0"
Padding="0"
BackgroundColor="Transparent"
>
<Image
Source="{Binding Image.Source}"
Aspect="AspectFill"
HeightRequest="{Binding Image.HeightRequest}"
BackgroundColor="Transparent"
VerticalOptions="Center"
>
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ClickGestureCarouselOnlyCommand}" />
</Image.GestureRecognizers>
</Image>
</Border>
</Grid>
</Border>
</DataTemplate>
</CarouselView.ItemTemplate> So maybe u could use this image tap workaround for your case. |
@npostma I'm using 7.0.0-ci.net7.19653 on Windows right now. .NET 8 is crashing for me altogether. Your code is not a workaround for me. |
Not even when you overlay you carousel card with an invisible transparant image that holds the TapGesture? (Like a 1x1 px stretched image). I know, no one wants that, but we need tobe creative for now 🤔 With a grid you can 'stack' cels. |
@npostma I can't overlay my CollectionView items because they contain buttons and entry fields. |
This issue is an agglomeration of about half a dozen different issues, so I'm going to do my best to address them all. First off - if you've seen issues on iOS where some tap gestures on a page fire and others further down do not, and your items are inside of a ScrollView: you might have been hitting a variation of #14257. It's not a gesture issue, it's a ScrollView issue. It's been addressed in .NET 8, and it's on the consideration list for backporting to .NET 7. We've also addressed some issues on iOS in .NET 7 and 8 with layouts on iOS not having user interaction enabled; you may have run into these, and now they're fixed. If you had problems with TapGestures on Grids, StackLayouts, ContentViews, Borders, Frames, etc., this may have been your actual issue. We've fixed some problems with Frame on Android which may have been preventing TapGesture from firing reliably. We've also addressed some interaction issues with Frames as parts of DataTemplates, so if you've had a problem with DataTemplates containing Frames not honoring your TapGestures, that's likely been fixed. If you're having problems with gestures on Spans, we're tracking that issue at #4734. Because this issue has become so large and contains so many sub-issues unrelated to the original problem, we're asking that anyone who is still experiencing problems with TapGesture on controls to open an issue specific to their situation so that we can address them appropriately. We will be closing this issue. |
To address the original issue from the original poster: CheckBox, Switch, and RadioButton intentionally do not have Command properties because that would be contrary to the nature of the controls. They are not intended to initiate action, they are intended to modify state. While it's possible to force a Command on them by adding a TapGesture, that's not a recommended way to use them. A TapGesture on a control may (depending on the platform) intercept user touches and prevent interaction with the underlying control; it might not toggle the state. Also, other ways of toggling the control (programmatic, or via alternate input methods) may not cause the intended Command to run. If you need to run some sort of additional logic when a CheckBox/RadioButton is checked/unchecked or a Switch is toggled, you have a couple of options:
All that being said, TapGesture does now fire on the controls in question. But I highly recommend that you do not use TapGesture to force a Command on an inappropriate control. |
This issue has been moved from a ticket on Developer Community.
[severity:It’s more difficult to complete my work]
The following is working perfectly fine:
While this is not working:
The command is not executed.
The same goes for the Switch.
If this is intentional, what would be the proper way to bind a command to the Checkbox or Switch?
Original Comments
Feedback Bot on 7/17/2022, 08:01 PM:
(private comment, text removed)
Original Solutions
(no solutions)
Depends on
The text was updated successfully, but these errors were encountered: