I have a grid where there are 3 columns containing 2 buttons and 1 label. What I want is to add a Tap gesture to each rows in the grid. I want the click event to be fired when the user taps anywhere in the grid row. Is there any way to do this?
I want to keep my layout as simple as possible. Before I was creating 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.
As you can see, we define four Columns in the DataTable called RowNumber, Column1, Column2 and Column3. The RowNumber column will serve as the key for generating the rows in the GridView. Noticed that for Columns 1, 2 and 3, I assigned an empty value for those columns since the GridView will be generated for the first time.
To get started, let’s grab a GridView control from the Visual Studio Toolbox and put it in the Web Form. The mark up would look something like this: Since this demo is intended to generate rows of TextBox in GridView, then we set up some Template Fields columns so that GridView will automatically generates TextBoxes when a new row is being added.
In the DataGrid element, add a RowDetailsTemplate element. Create a DataTemplate that defines the appearance of the row details section. The following XAML shows the DataGrid and how to define the RowDetailsTemplate inline. The DataGrid displays three values in each row and three more values when the row is selected.
It is necessary to use the GridView.SetRowCellValue method if you wish to assign a value to a cell as described in the Obtaining and Setting Cell Values help article. However, if you deal with an unbound column, such a column does not have any data storage.
I would suggest adding a ContentView
(which is not as intensive as a StackLayout
). Make it cover the whole row and add the GestureRecognizer
to that, like so:
<ContentView HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="3">
<ContentView.GestureRecognizers>
<TapGestureRecognizer Tapped="OnTapped"/>
</ContentView.GestureRecognizers>
</ContentView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With