Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically show a keyboard for textbox?

I have one textbox on a windows phone page and I want to show keyboard as soon as the page is loaded.

Is there any way to make this textbox already focused when I navigate to this page?

I considered using Guide.BeginShowKeyboardInput() but I don't think it's a good solution in silverlight.

like image 521
WholeLifeLearner Avatar asked Sep 18 '12 16:09

WholeLifeLearner


2 Answers

Override the OnNavigatedTo method for the page.

protected override void OnNavigatedTo(NavigationEventArgs e)
{
  base.OnNavigatedTo(e);

  // Set focus to the TextBox, this will pop up the 
  // virtual keyboard
  myTextBox.Focus();
}
like image 42
Praetorian Avatar answered Nov 15 '22 06:11

Praetorian


Yeah, I wouldn't manually show the keyboard. It may be an annoyance for those that have devices with a physical keyboard. In the load event for the page you could just call the Focus method on the textbox that you want to be selected. The Keyboard should automatically show as necessary.

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
            txtLongitude.Focus();
}
like image 94
Joel Avatar answered Nov 15 '22 05:11

Joel