I managed to fix it by adding a line of code. I think I'm very dumb.
var cell = cellContent.Parent as DataGridCell;
if (cell != null)
{
cell.Focus();
var textBox = cellContent as TextBox;
if (textBox != null)
{
textBox.SelectAll();
textBox.Focus(); // this line
}
}