WPF: Cannot set focus
问题 I want that from the PreviewTextInput handler a new control is created and focus is set to it. But even after calling Focus() on the new control, the cursor is still in the old textbox. The handler UserControl_PreviewTextInput is registered on the UserControl which contains this textbox if this matters. private void UserControl_PreviewTextInput(object sender, TextCompositionEventArgs e) { CodeLineControl el = new CodeLineControl(); container.Children.Insert(idx+1, el); el.innerTextBox.Focus()