private void CommentButton_Click(object sender, RoutedEventArgs e) { //The comment button will go into or out of the Comment Box var button = sender as UIElement; if (button != null) { var textbox = UIElementHelper.FindNear <TextBox>(button); if (textbox != null) { if (textbox.IsVisible) { if (textbox.IsFocused) { button.Focus(); RaiseFocusChanged(new RoutedEventArgs()); } else { textbox.Focus(); textbox.CaretIndex = textbox.Text.Length; RaiseFocusChanged(new RoutedEventArgs()); } } } } }