How can I set the focus of a TextBox in WPF
I want to have focus in my TextBox
after it is double-clicked.
I simply try:
myTextBox.Focus()
The caret appears however it is not blinking, and no one can type in the text box.
What is the proper way to set the keyboard input focus on a Tex开发者_StackOverflowtBox
?
Old question, but it was the first to come in a search and I don't see a valid answer, so posting one.
Problem is probably that your TextBox has Logical Focus, but not Keyboard Focus. Logical focus is set per scope, and WPF allows you to have multiple Focus Scopes in your application, so multiple controls can be logically focused, however only one control in your application can have Keyboard Focus.
myTextBox.Focus(); // Will set Logical Focus for myTextBox's Focus Scope
Keyboard.Focus(myTextBox); // Will set Keyboard Focus to myTextBox
精彩评论