The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
Preventing TextBox losing Focus on Button Click RRS feed

  • Question

  • I have the scenario where I have a user typing in a textbox, and then additional buttons below.

    When a button is clicked however the TextBox loses focus and the Keyboard is dismissed.

    How can I prevent this behaviour?

    The buttons are in a control template so have no option to set focus back to the textbox on the click event.

    Tuesday, January 12, 2016 12:15 PM

All replies

  • You must get reference to textbox from some event (maybe LostFocus) by casting sender to TextBox and then use it to set the focus.

    Check my apps: Share to Speech and File Cards

    Tuesday, January 12, 2016 7:04 PM
  • What type of app? Please edit your subject line per Guide to posting: subject line tags

    There are different answers based on the type of app you're writing and the specific scenario. Setting the focus back in the click event is one of the uglier options and shouldn't be necessary.

    Tuesday, January 12, 2016 9:28 PM