Skip to content

Synctest-hub/How-to-bind-button-command-to-ViewModel-from-DataGridTemplateColumn-of-DataGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

How to bind button command to ViewModel from DataGridTemplateColumn of DataGrid?

The .NET MAUI DataGrid allows you to bind command property of button inside DataGridTemplateColumn 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

<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>

View sample in GitHub

Take a moment to pursue this documentation, where you can find more about Syncfusion .NET MAUI DataGrid (SfDataGrid) with code examples. Please refer to this link to learn about the essential features of Syncfusion .NET MAUI DataGrid(SfDataGrid).

Conclusion

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

You can refer to our .NET MAUI DataGrid's feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data. For current customers, you can check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET MAUI DataGrid and other .NET MAUI components. If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac or feedback portal. We are always happy to assist you!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages