Articles in this section
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>

 

Sample

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied