简体   繁体   中英

Check if software keyboard is open in Windows Phone 8?

I want to check if the software keyboard is open in Windows Phone 8. I have found some sparse information that this is possible using CoreWindow.IsKeyboardInputEnabled, but I can't find any way to implement this. I have found sample code only for C++, which I don't understand at all.

I use VB, however I can read C# enough to figure it out if I can get a C# example.

Whatever I do I always get a null/nothing value. The following code compiles and runs, but c is 'nothing' when the app crashes at the if c.IsKeyboarInputEnabled... line.

Dim c as CoreWindow
c = CoreWindow.GetForCurrentThread
if c.IsKeyboardInputEnabled then...

I know I need to give 'c' a value, but can't figure out how. I've also tried:

Dim c as CoreWindow = New CoreWindow

which the editor flags as an error and thus won't compile.

If it's relevant, what I am trying to do is ensure my navigation is consistent. Currently, a tap on a particular screen element should close that element. However, if the keyboard is open, I want that tap to simply close the keyboard and leave the tapped item open. I believe this is the more intuitive and consistent approach for the user.

I think the only way to achieve this functionality is to know if the keyboard is open before determining what to do with any open panels.

eg [when screen tapped and a popup is expanded]

If [keyboard visible] then [close keyboard] else [close tapped item]

I don't think there is any official API to detect the opening and closing of the SIP but one workaround might be to check if any of your TextBoxes have focus.

You can do this by overriding GetFocus and LostFocus for each TextBox.

To close keyboard, just set the focus to the ContentPanel(or any other grid).

Let me know if this works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM