C# – Cursor Focus on Textbox in WPF/C#

c++textboxwpf

I am currently in the process of creating a Onscreen keyboard. I am handling the button click using routedcommands. The issue is that when i click on the button in keyboard panel the focus shifts to the button rather than on the Textbox. The requirement states that a cursor should always appear in the text box to indicate the position where the next character will be inserted. Is there a way i can keep focus on the textbox while button is clicked.

Best Solution

To set logical focus to an input control

FocusManager.SetFocusedElement(this, textboxJack);     // set logical focus

To set keyboard focus to an input control

Keyboard.Focus(textboxJill);                             // set keyboard focus

To know the difference between logical and keyboard focus

Input Overview - Focus on MSDN