I have a datagrid consisting primarily of TemplateColumns. I am having the issue where when tabbing through the row, it appears to go to the cell, then the content within the cell (ie a textbox or togglebutton). The ideal situation is that tabbing through the columns puts the focus on the content and skips the cell. I may be interpreting what is happening incorrectly, but visually it appears to be the case. I have tried:
<DataGridTemplateColumn Header="Group Value"
MinWidth="30"
Width=".02*">
<DataGridTemplateColumn.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="IsTabStop"
Value="False" />
</Style>
</DataGridTemplateColumn.CellStyle>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding SomeBinding,
ValidatesOnDataErrors=True,
UpdateSourceTrigger=PropertyChanged}"
IsReadOnly="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type DataGrid}},
Path=DataContext.IsReadOnly}"
Style="{StaticResource TextBoxStyle}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
But that doesn’t work as I assumed it would. Can anyone help me?
Thanks
You are correct, it does seem to focus the
DataGridTemplateColumnbefore it focuses on the control within it while tabbing.In my search for a solution, I came across this:
http://iyalovoi.wordpress.com/2009/08/21/wpf-datagrid-tabbing-from-cell-to-cell-does-not-set-focus-on-control/
You can attach the
FocusAttacherto the control within the template column, and it will steal the focus from it. It worked great for me.