I have a DataGrid
and I want to turn off SelectAll()
method on DataGrid
.
To be precise this button:
Here is Executed
event which will be handled in code behind:
<DataGrid ItemsSource="{Binding EmployeeDataTable}" Name="dataGrid">
<DataGrid.CommandBindings>
<CommandBinding Command="ApplicationCommands.SelectAll"
Executed="SelectAll_Executed">
</CommandBinding>
</DataGrid.CommandBindings>
</DataGrid>
code behind:
private void SelectAll_Executed(object sender, ExecutedRoutedEventArgs e)
{
//dataGrid.SelectAll();//I commented this line so user cannot select all rows
//in a datagrid
}
The above code perfectly works and a user cannot select all rows in DataGrid and that is what I want. But I want to move handler of event(SelectAll_Executed
) to viewModel.
What I've tried:
<DataGrid ItemsSource="{Binding EmployeeDataTable}" Name="dataGrid">
<DataGrid.CommandBindings>
<CommandBinding Command="ApplicationCommands.SelectAll" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Executed">
<i:InvokeCommandAction Command="{Binding Path=SomeCommand, Mode=OneWay}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</CommandBinding>
</DataGrid.CommandBindings>
</DataGrid>
But I've met such error:
The attached property "Triggers" can only be applied to types that are derived from "DependencyObject". DataGridAddedColumns
How to handle Executed event of CommandBinding using MVVM rules?