have a TextBox item (MyTextBox) on a TabItem control. I have code that looks as follows:
MyTextBox.Focus();
Keyboard.Focus(MyTextBox);
When I run this code through the debugger I see the following after the lines are executed:
MyTextBox.IsFocused = true
MyTextBox.IsKeyboardFocused = false
Can anyone tell me why the textbox isn’t receiving keyboard focus? It’s just a standard TextBox control that is enabled.
MyTextBox.IsKeyboardFocusedis false because you are looking at it under debugger and the keyboard focus is probably in your Visual Studio… Try debugging focus without breakpoints (e.g.Debug.Writeor trace brakepoints) to see actual values ofMyTextBox.IsKeyboardFocusedin runtime.Also notice that
Focus()method returns boolean value that indicates whether focus was successfully set. Does it returnFalsein your case? If yes, I would suggest stepping intoFocus()method in order to find out what is wrong.