Checkbox with Catel EventToCommand not working in Datagrid

289 Views Asked by At

I have the following XAML:

<DataGrid.Columns>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
      <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"
         Command="{Binding DataContext.UpdateCommand, RelativeSource={RelativeSource Mode=Self}}">
      </CheckBox>
   </DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

In the viewmodels I have;

public Command UpdateCommand { get; private set; }
UpdateCommand = new Command(UpdateControls);

private void UpdateControls()
{
    //Execute
}

However, UpdateControls is never executed. Can anybody help me with this to get this working ?

1

There are 1 best solutions below

0
On BEST ANSWER

The problem is that you are binding to yourself (which is the CheckBox). You should give the DataGrid a name and then use this binding:

<CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay}"
          Command="{Binding ElementName=myDataGrid, Path=DataContext.UpdateCommand}" />