Category / Section
How to bind button command to ViewModel from TemplateColumn of DataGrid?
1 min read
You can bind command property of button inside GridTemplateColumn to a property in ViewModel, by binding command with source as SfDataGrid BindingContext using x:Reference. Refer the below code example for more details.
XAML
<sfgrid:GridTemplateColumn MappingName="ShipCountry" > <sfgrid:GridTemplateColumn.CellTemplate> <DataTemplate> <Button WidthRequest="100" Text="Delete" Command="{Binding Source={x:Reference dataGrid}, Path=BindingContext.DeleteRecordCommand}" CommandParameter="{Binding .}" /> </DataTemplate> </sfgrid:GridTemplateColumn.CellTemplate> </sfgrid:GridTemplateColumn>