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
Your problem can be solved by using a separate focus scope for your "keyboard". Just apply the following property to the control that contains all of your buttons and then they will be in a separate focus scope and will not have the focus set to them when clicked
FocusManager.IsFocusScope="True"
Get the reference for the specific control(in that case TextBox). After click, in Button_Click method paste this:
Dispatcher.BeginInvoke((ThreadStart)delegate
{
control.Focus();
});
The way I solved this problem was to set focusable=false
to all the buttons/controls on the keyboard. That way you don't lose focused of the current control.
Textbox.Focus();
this will focus on the textbox
I had to use this to get my desired result
FocusManager.SetFocusedElement(this, UserNameautoCompleteBox);
Key key = Key.Enter; // Key to send
var target = Keyboard.FocusedElement; // Target element
RoutedEvent routedEvent = Keyboard.KeyDownEvent; // Event to send
target.RaiseEvent(
new KeyEventArgs(
Keyboard.PrimaryDevice,
PresentationSource.FromVisual(UserNameautoCompleteBox),
0,
key) { RoutedEvent = routedEvent }
);
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