Tab Between Fields With Virtual Keyboard

Posted: February 9, 2012 in Windows Phone 7 & Mango

If you have multiple TextBox controls on you screen, you might want the user to just press the enter key on the virtual keyboard to tab between them. To do this. you need to capture the KeyDown event of the control as follows:

<TextBox x:Name="TextBox1" InputScope="Text" KeyDown="TextBox1_KeyDown"/>
<TextBox x:Name="TextBox2" InputScope="Text" KeyDown="TextBox2_KeyDown"/>
<TextBox x:Name="TextBox3" InputScope="Text"/>

Now in the code behind file you can handle the navigation as follows:

private void TextBox1_KeyDown(object sender, KeyEventArgs e)
{
    if(e.Key.Equals(Key.Enter))
    {
        TextBox2.Focus();
    }
}

private void TextBox2_KeyDown(object sender, KeyEventArgs e)
{
    if(e.Key.Equals(Key.Enter))
    {
        TextBox3.Focus();
    }
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s