3

I have a textbox with a button inside (Telerik's RadTextBox with an Action configured). When the user presses the Action, a progress bas is displayed, the screen goes dark, and some magic happens.

My problem is that since the action doesn't result in the textbox losing focus, the on-screen keyboard is not hidden, and keeps covering half the screen.

I would like to programmatically hide the on-screen keyboard, but don't know how.

SaguiItay
  • 2,145
  • 1
  • 18
  • 40

3 Answers3

9

Just set focus to the main page:

this.Focus();

this will focus a control that doesn't use the keyboard and thus hide the keyboard. Unfortunately there is no API to the keyboard to hide it.

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
  • 1
    @matthewsheets and welcome to the world of changing API's and OS implementations! – Mike Perrenoud Jul 27 '15 at 17:16
  • I just tried it on Win 10 Mobile and it worked just fine. Maybe they changed the API again :p Wait wait, I take it back. Now it works only on some pages. It seems like, the first element on the page must not be an input field, or it will get selected automatically first, if you call this.Focus() and the Keyboard is up and running again – FloppyNotFound Aug 04 '17 at 14:43
2

Instead try disabling and then enabling the textbox in question in an appropriate place (like once a query has been submitted or an action triggered):

   TextBox.IsEnabled = false;
   TextBox.IsEnabled = true;

(Via https://stackoverflow.com/a/23905874/1963978)

Not clean, but it does the job (in Windows 10 mobile).

Community
  • 1
  • 1
matthewsheets
  • 4,535
  • 2
  • 15
  • 11
  • ugly, yet does the trick on Win10 also with JavaScipt UWP apps `(that.control.disabled = true; that.control.disabled = false;)` – sebagomez Dec 13 '15 at 15:31
0

here lot solution is available for a Textblock only but in my case AutoCompleteBox

  <toolkit:AutoCompleteBox Name="autoComplateTxt"
                                             Grid.Row="4"
                                             Margin="15,5,2,10"
                                             Padding="0"
                                             Height="65"
                                             Text=""
                                             BorderThickness="1"
                                             BorderBrush="Black"
                                             VerticalAlignment="Center"
                                             
                                          DropDownClosed="autoComplateTxt_DropDownClosed"
                                              />
 private void autoComplateTxt_DropDownClosed(object sender, RoutedPropertyChangedEventArgs<bool> e)
    {
        this.Focus();
    }
Lalit kumar
  • 2,377
  • 1
  • 22
  • 17