I am using the datagrid from WPF toolkit in a WPF windows application. It has a datatemplate in the rowheader which creates a checkbox column used for selecting the rows.
If you click on the header row of the checkbox column (the top leftmost cell in the grid), it will check all the checkboxes in the grid thereby selecting all the rows.
Relevant portions from the xaml
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit" >
<toolkit:DataGrid Name="dataGrid" ItemsSource="{Binding}"
AutoGenerateColumns="True" SelectionMode="Extended" CanResizeRows="False">
<toolkit:DataGrid.RowHeaderTemplate>
<DataTemplate>
<Grid>
<CheckBox IsChecked="{
Binding Path=IsSelected,
Mode=TwoWay,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type toolkit:DataGridRow}}}"
/>
</Grid>
</DataTemplate>
</toolkit:DataGrid.RowHeaderTemplate>
</toolkit:DataGrid>
</Window>
Now I want to know how to handle this click. I plan to handle that and show a popup menu instead.
Which control's click event should I wire for this?
Answer: using SelectAllCommand to handle the events like so (example)
datagrid.CommandBindings.Add(new CommandBinding(
Microsoft.Windows.Controls.DataGrid.SelectAllCommand,
OnSelectAll, CanExecuteSelectAll));
public void OnSelectAll(object sender, ExecutedRoutedEventArgs e)
{
MessageBox.Show("All Selected");
}
public void CanExecuteSelectAll(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
Console.WriteLine("Can I execute?");
}