private void Text_PreviewKeyDown(object sender, KeyEventArgs args) { TextBox source = (TextBox)args.Source; int value, min, max; GetFieldInfo(source, out value, out min, out max); if (args.Key == Key.Down && Keyboard.Modifiers == ModifierKeys.None) { value--; if (value < min) { value = max; } args.Handled = true; SetTimeComponent(value, source); UpdateTexts(); } if (args.Key == Key.Up && Keyboard.Modifiers == ModifierKeys.None) { value++; if (value > max) { value = min; } args.Handled = true; SetTimeComponent(value, source); UpdateTexts(); } if (args.Key == Key.Left && Keyboard.Modifiers == ModifierKeys.None) { if (source.SelectionLength == source.Text.Length || source.SelectionLength == 0 && source.SelectionStart == 0) { if (source == YearText) { SecondText.Focus(); } else { source.MoveFocus(new TraversalRequest(FocusNavigationDirection.Previous)); } args.Handled = true; } } if (args.Key == Key.Right && Keyboard.Modifiers == ModifierKeys.None) { if (source.SelectionLength == source.Text.Length || source.SelectionLength == 0 && source.SelectionStart == source.Text.Length) { if (source == SecondText) { YearText.Focus(); } else { source.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next)); } args.Handled = true; } } }