tags:

views:

4965

answers:

3

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.

+2  A: 

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

http://msdn.microsoft.com/en-us/library/ms754010.aspx#text_input

Gishu
A: 

I like these do-my-homework-for-me questions; "the requirement states"...priceless. For those who find this via Google, the trick to progmatically moving the cursor in a WPF TextBox is to use the SelectioNStart property.

private void Button_Click(object sender, RoutedEventArgs e)
{
    textBox.Focus();
    textBox.SelectionStart = textName.Text.Length;
}
Josh Fischer
A: 

Try setting Focusable="False" on the button.

Bill Lefler