Add GestureRecognizer to row in gridview

I have a grid in which there are 3 columns containing 2 buttons and 1 label. I want to add a Tap gesture to each grid line. I want the click event to fire when the user is thrown somewhere on the grid line. Is there any way to do this?

I want my layout to be as simple as possible. Before I created the same grid using multiple stacklayouts and adding gestures to the parent stacklayout. But for performance, I want to do this using a grid view.

+5
source share
2 answers

I solved this by adding a view of the content and a gesture to it in each row and sweeping it across my columns to cover the entire row, so clicking anywhere in the row will trigger a switch event for each row.

<ContentView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"> <ContentView.GestureRecognizers> <TapGestureRecognizer Tapped="OnTapped"/> </ContentView.GestureRecognizers> </ContentView> 
+1
source

I would suggest adding a ContentView (which is not as intense as StackLayout ). Make it span the entire line and add a GestureRecognizer to this, for example:

 <ContentView HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Row="0" Grid.Column="0"> <ContentView.GestureRecognizers> <TapGestureRecognizer Tapped="OnTapped"/> </ContentView.GestureRecognizers> </ContentView> 
+6
source

All Articles