How to Make Label Clickable in .NET MAUI DataGrid?
In this article, we will show you how to make a label clickable inside the DataGridTemplateColumn in .NET MAUI DataGrid.
xaml
The code below demonstrates how to make a label clickable inside the DataGridTemplateColumn.
<ContentPage.BindingContext>
<local:EmployeeViewModel x:Name="viewModel" />
</ContentPage.BindingContext>
<syncfusion:SfDataGrid x:Name="dataGrid"
ItemsSource="{Binding Employees}"
ColumnWidthMode="Auto"
AutoGenerateColumnsMode="None"
GridLinesVisibility="Both"
HeaderGridLinesVisibility="Both">
<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridNumericColumn MappingName="EmployeeID"
Format="#"
HeaderText="Employee ID" />
<syncfusion:DataGridTemplateColumn MappingName="Name"
HeaderText="Employee Name">
<syncfusion:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Text="{Binding Name}" Padding="12"
HorizontalTextAlignment="Start"
VerticalTextAlignment="Center">
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped" />
</Label.GestureRecognizers>
</Label>
</DataTemplate>
</syncfusion:DataGridTemplateColumn.CellTemplate>
</syncfusion:DataGridTemplateColumn>
<syncfusion:DataGridTextColumn MappingName="Title"
HeaderText="Designation" />
<syncfusion:DataGridDateColumn MappingName="HireDate"
HeaderText="Hire Date" />
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
C#
private void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
{
var customerName = (sender as Label).Text;
DisplayAlert("Customer Name", $"Name : {customerName}", "ok");
}
Output
Download the complete sample from GitHub.
Conclusion
I hope you enjoyed learning how to make the label clickable in .NET MAUI DataGrid.
You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations and documentation to understand how to present and manipulate data.
For current customers, check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!