Friday, September 23, 2011

Tabbing is misbehaving inside DataGrid with custom controls (GenerateElement)

Context: I created a DataGridBoundColumn class that creates my own control.
Problem: tabbing between cells (that were created using the GenerateElement), causes tabbing to go through DataGridCell (the container of your generated element) then your element. So it will require the user to press TAB twice to go to the next cell.
Solution: The elements that you generate using GenerateElement (not edit mode cells), need to update some of its properties: Focusable = false, IsHitTestVisible = false, and finally set its IsTabStop to false (use this line: noeditingElement.SetValue(KeyboardNavigation.IsTabStopProperty, false);)

Conclusion: Elements created using GenerateElement should be NOT focusable , NOT hit visible, or tab stop disabled.

No comments: