Search code examples
wpfxamlcatel

Checkbox with Catel EventToCommand not working in Datagrid


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 ?


Solution

  • 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}" />