private static void TryFocusNeighbourControl(TextBox currentControl, TextBox leftControl,
TextBox rightControl, Key keyPressed)
{
if (keyPressed == Key.Left &&
leftControl != null &&
currentControl.CaretIndex == 0 )
{
leftControl.Focus();
}
else if (keyPressed == Key.Right &&
rightControl != null &&
//if the caret index is the same as the length of the text and the user clicks right key it means that he wants to go to the next textbox
currentControl.CaretIndex == currentControl.Text.Length )
{
rightControl.Focus();
}
}