NOTE: I knew where I'm getting null but don't know how to set reference to it for that particular scenario.Checking & unchecking very thing works perfect. Only Key press event handling for checkbox at header column I'm facing trouble.
I had CheckBox
on a column header and default focus is on that check box. I also have DataGrid_KeyDownEvents()
where it handles Enter key
event. when ever I press Enter Key it CurrentCell.Column.Header Column
gets null when the focus is on Column Header checkbox. my question is how do I can set object reference instance of an object correctly.
<DataGrid.Columns>
<DataGridTemplateColumn Header="" Width="50" >
<DataGridTemplateColumn.HeaderTemplate> <!--<column header>-->
<DataTemplate>
<CheckBox DataContext="{Binding ElementName=xyz, Path=DataContext}"
IsChecked="{Binding IsAllChecked, Mode=TwoWay}" Style="{DynamicResource CheckBoxStyle}" HorizontalAlignment="Center" VerticalAlignment="Center"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
<DataGridTemplateColumn.CellTemplate> <!--<rows>-->
<DataTemplate>
<CheckBox Style="{DynamicResource CheckBoxStyle}" HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding IsMarked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding CanBeMarked, Converter={StaticResource BoolToVisConverter}}"></CheckBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
DataGrid_KeyDownEvents()
if ((e.Key == Key.Enter || e.Key == Key.Return))
{
if (this.CurrentCell.Column.Header.ToString() == XColumnName)
{
//do something
}
}
What I'm excepting from above code is <DataGridTemplateColumn.HeaderTemplate>
check box on column header reference is to handle but I'm getting Null reference in column object this.CurrentCell.Column.Header
. and the check boxes in gridRows are getting reference as good as enough.