We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to fire the events in SfDataGrid by using the commands defined in the ViewModel?

Platform: Xamarin.Forms |
Control: SfDataGrid
Tags: event, commands

Events in SfDataGrid can be fired by using commands with the help of Xamarin.Forms.Behaviors. The Xamarin.Forms.Behaviors allows you to convert events into commands. To use it, you need to install the Xamarin.Forms.Behaviours NuGet in your application which can be find in the below link.

NuGet Link: https://www.nuget.org/packages/Xamarin.Forms.Behaviors/

Refer the below code example in which Xamarin.Forms.Behaviors has been used to convert the SelectionChanged event in SfDataGrid into command.


<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
            xmlns:local ="clr-namespace:SampleDemo;assembly=SampleDemo"
    <local:ViewModel x:Name="viewModel" />
  <sf:SfDataGrid x:Name="dataGrid"
                 ItemsSource ="{Binding OrderInfo}">
        <b:EventToCommand EventName="SelectionChanged"
                          Command="{Binding SelectionCommand}" />



private Command selectionCommand;
public Command SelectionCommand
    get { return selectionCommand; }
    set { selectionCommand = value; }
public ViewModel()
    selectionCommand = new Command(onSelectionChanged);
private void onSelectionChanged()




You can download a working sample for this KB here.

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile