I have a WPF DataGrid and want to set the focus to the first item so that the user can navigate with the keyboard in the list of items, when the dialogue is opened the first
Ok, I found a solution. This works for me
Keyboard.Focus (GetDataGridCell (dataGridFiles.SelectedCells[0]));
private System.Windows.Controls.DataGridCell GetDataGridCell (System.Windows.Controls.DataGridCellInfo cellInfo)
{
var cellContent = cellInfo.Column.GetCellContent (cellInfo.Item);
if (cellContent != null)
return ((System.Windows.Controls.DataGridCell) cellContent.Parent);
return (null);
}
Now, I got the right focus and can navigate with keyboard.