Articles in this section
Category / Section

How to bind button command to viewmodel from DataGridTemplateColumn of .NET MAUI DataGrid?

2 mins read

The .NET MAUI DataGrid allows you to bind the command property of a button inside DataGridTemplateColumn to a property in the ViewModel, by binding the command with source as the SfDataGrid’s BindingContext using x:Reference. Refer to the code example below for more details.

XAML

<syncfusion:DataGridTemplateColumn HeaderText="ID Number" MappingName="IDNumber">
    <syncfusion:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Button WidthRequest="100" Text="Delete" HeightRequest="40" BackgroundColor="AliceBlue" TextColor="Black"
            Command="{Binding Source={x:Reference datagrid}, Path=BindingContext.DeleteRecordCommand}"
            CommandParameter="{Binding .}" />
        </DataTemplate>
    </syncfusion:DataGridTemplateColumn.CellTemplate>
</syncfusion:DataGridTemplateColumn>

Download the complete sample from GitHub

Conclusion
I hope you enjoyed learning how to bind a button command to a ViewModel from a DataGridTemplateColumn of a DataGrid.

You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.

For current customers, check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components.

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, or the feedback portal. We are always happy to assist you!

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