Search code examples
c#wpfkeyboardfocus

Is there a way to set Keyboard.FocusedElement to a specific element?


Keyboard.FocusedElement gives the element that has keyboard focus. However it has no setter. I want to set this property to another element through code. is there a way?

On microsoft's site, it said this: "Keyboard focus refers to the object that is receiving keyboard input. The element with keyboard focus has IsKeyboardFocused set to true."

However IsKeyboardFocused also has no setter as well.


Solution

  • I think you are just looking for the UIElement.Focus() method.