How to make Back button go back when you have the on-screen keyboard visible?
I have a simple input form that consists of a sing开发者_如何学JAVAle textbox and an "OK/Cancel" buttons. To save the user some taps, I bring the focus to the text box when the page is shown, so the keyboard pops up. At this point, I want the "Back" button to behave the same as cancel and navigate back if pressed, but what the thing actually does, it just removes the focus from the text box without even firing the BackKeyPress event. On the next press it does move back, but this is two clicks instead of one.
So I have two questions
- How to make the back button "go back" even when the keyboard is visible?
- Am I trying to do something bad from the standpoint of the WP7 interaction design?
What you can do is handle the textbox's KeyUp method. When a key is pressed, check if it's the hardware back key. In my test, the hardware back key has a PlatformKeyCode
of 27. I'm not sure if this changes between hardware devices. However, assuming it doesn't, you could do the following:
private void TextBox_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
{
if(e.PlatformKeyCode == 27)
{
//Navigation code
}
}
As to whether this is a good idea, I'm not sure. The primary function of the back key, in regards to the on-screen keyboard, is to close the keyboard. This is what users will mostly experience throughout various applications, so that's what they might expect from yours. However, since you're SIP is automatically displayed, I guess you could argue it's almost part of the layout itself. I couldn't see anything in the UI Guidelines about it, but you should have a read in case I've missed something.
Have you checked if you can override the OnBackKeyPressed method?
In terms of what you're allowed to do with the Back key, from the Application Certification guidelines:
5.2.4 Use of Back Button
To maintain a consistent user experience, the Back button must only be used for backwards navigation in the application.
a. Pressing the Back button from the first screen of an application must exit the application.
b. Pressing the Back button must return the application to the previous page.
c. If the current page displays a context menu or a dialog, the pressing of the Back button must close the menu or dialog and cancel the backward navigation to the previous page.
d. For games, when the Back button is pressed during gameplay, the game can choose to present a pause context menu or dialog or navigate the user to the prior menu screen. Pressing the Back button again while in a paused context menu or dialog closes the menu or dialog
This SO question might also be useful....
I'm going to agree with keyboardP that you shouldn't really override the default behaviour of how the SIP interacts with the hardware back button, but you could always submit it and see what happens :)
精彩评论