locked
How to remove focus from the textbox

    Question

  • Hi,

    I have a combo box and textbox in my windows store app.

    when I testing app in tablet windows8.1 when I clicked on combo box the soft keyboard still opened even after writing the below code also.

    privatevoidscopeComboBox_Tapped(objectsender, TappedRoutedEventArgse)

            {

                e.Handled =

    true;

               

    //  threadSearchbox.IsTabStop = false;


                threadSearchbox.Focus(

    FocusState.Unfocused);

            }


    srujana

    Thursday, April 23, 2015 11:58 AM

Answers

  • What were you trying there?
    Just because you set the textbox to readonly doesn't mean the soft keyboard will disappear.
    Tapping somewhere on the screen should let the keyboard disappear (though there are some cases were that's not the case).
    I just tried and the keyboard shouldn't open when you click the combobox.
    It will however stay open if you click on the textbox and afterwards on the combobox.
    I don't really get why you'd want to hide the keyboard though. In most cases it's better to let the user decide if he wants to hide it.
    But if you're sure you need to close it programmatically then just set the focus to a button that's offscreen and has no function. That should close the keyboard.
    And you probably should use the GotFocus event for the combobox instead of the tapped event.
    Friday, April 24, 2015 11:00 AM

All replies

  • Hey,

    I'm not sure if it's normal that the software keyboard opens when the focus is on a combobox.
    If you've set IsEditable to true I'm pretty sure it's normal for it to open.
    If you kept it on its default value (false) it could still be that selecting a combobox opens the soft keyboard because you could also type to select an option. I'd have to try that to be sure though.
    However what you are trying won't work.

    Take a look at "Remarks" here:
    https://msdn.microsoft.com/en-uS/office/office365/hh702161.aspx

    You'd have to set the focus to another element. Afaik there is no way to simply unfocus an element programmatically.
    If you find one please tell me.

    Thursday, April 23, 2015 12:34 PM
  • I have tried the below code , but was not helpful

    privatevoidthreadSearchbox_GotFocus(objectsender, RoutedEventArgse)

            {

                threadSearchbox.IsReadOnly =

    false;

            }

    privatevoidscopeComboBox_Tapped(objectsender, TappedRoutedEventArgse)

            {

                e.Handled =

    true;

                threadSearchbox.IsReadOnly =

    true;

               

    //  threadSearchbox.IsTabStop = false;


               

    //if (threadSearchbox.FocusState == FocusState.Programmatic)


               

    //threadSearchbox.Focus(FocusState.Unfocused);


            }


    srujana

    Friday, April 24, 2015 5:01 AM
  • What were you trying there?
    Just because you set the textbox to readonly doesn't mean the soft keyboard will disappear.
    Tapping somewhere on the screen should let the keyboard disappear (though there are some cases were that's not the case).
    I just tried and the keyboard shouldn't open when you click the combobox.
    It will however stay open if you click on the textbox and afterwards on the combobox.
    I don't really get why you'd want to hide the keyboard though. In most cases it's better to let the user decide if he wants to hide it.
    But if you're sure you need to close it programmatically then just set the focus to a button that's offscreen and has no function. That should close the keyboard.
    And you probably should use the GotFocus event for the combobox instead of the tapped event.
    Friday, April 24, 2015 11:00 AM