views:

345

answers:

3

Simple question: How do I detect that the onscreen keyboard has been displayed on windows mobile 7? Is there an event I can add a listener to?

It takes up about half the screen and I want to scroll the view up when it gets displayed...

EDIT:

A comment below indicates more clearly what I'm trying to do: I have a textbox input, and as the user types into it an autocomplete dropdown appears below it (like google suggest). By default, the active control (the textbox) scrolls into view when focussed, and the onscreen keyboard is directly below it. The onscreen keyboard appears in front of my autocomplete dropdown - what I want to do is make the screen scroll a little further up, so there's some room for my dropdown to be shown.

The windows phone UI design guidelines say: "When the keyboard is deployed, the application should scroll to ensure the active edit control and the caret are in view". This happens fine, it's just the non-active dropdown gets hidden behind the onscreen keyboard.

The guidelines also say that an application can choose to show the onscreen keyboard, and can also choose to close it.

At the moment i'm stuck, and I don't think (based on my research and the replies to this question) that it's possible to detect that the onscreen keyboard has been displayed. I'm moving my investigation to see if it's possible to determine the "visible area" of the page (width & height in pixels for example), and combine this with an onfocus for the textbox... not sure if this will prove fruitful though.

+2  A: 

You can listen to the TextBox.GotFocus and TextBox.LostFocus events to detect when a text box in your application acquires and looses focus.

Andréas Saudemont
I'd prefer to know that the onscreen keyboard has been shown - just because a textbox has got focus doesn't mean the onscreen keyboard was shown (for example, the phone might have a hardware keyboard)
David_001
Good point. As far as I know there's no way with the current Windows Phone SDK to detect when the virtual keyboard appears.
Andréas Saudemont
They might add an event that is triggered when the OnScreen Keyboard is displayed - something like this must already happen as when the SIP is shown it triggers some animations such as the Page Title element sliding up etc automatically, this event may be exposed at some point, if not already.
RoguePlanetoid
It's odd that the UI design guide for windows phone 7 states that the application should ensure the active control is scrolled into view whenever the onscreen keyboard is deployed, but there appears to be no way to detect when the onscreen keyboard has been deployed in the first place...
David_001
[I've raised the question in the Windows Phone 7 forum](http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/3ca0bffa-075b-4ad4-9db4-79b909737741). We'll see if anything comes up.
Andréas Saudemont
+1  A: 

If an editable element gets focus then the framework will automatically scroll the element into view. So you really shouldn't have to do anything.

Skeets
If you click on a textbox it scrolls into view, so that the keyboard is then directly below the control. However, I have an autocomplete dropdown that appears below the control, and the keyboard covers this up. I want the control to be at the top of the screen when the onscreen keyboard is shown...
David_001
+1  A: 

Detecting when the virtual keyboard is displayed won't be possible in 7.0, as confirmed by Microsoft's Peter Torr in the WP7 forum on MSDN.

Maybe, as a dirty workaround, you could detect when the position of your text box (or its parent scroll viewer's offset) has changed, as this would indicate that the virtual keyboard has appeared or disappeared.

Andréas Saudemont
Looks like it's not possible - hopefully microsoft will add it in to a service pack, or i'll need to rethink my design...
David_001