Reputation: 11341
I am working on a windows phone application.
I noticed that after I show up a textbox and a keyboard, if I press physical "back" key, the keyboard will hide, and press again it will go back to previous page.
But I want the page to navigate to previous page when the "back" key is press the first time. So its like the keyboard is up, when I press back key, it directly go back to the previous page.
I tried to implement the BackKeyPressed
event handler of the page but it does not seem work, since it is not called when the first time back key is pressed.
Anyone has any good idea with this? thank you
Upvotes: 1
Views: 1749
Reputation: 1088
You can implement a KeyUp eventhandler on the inputbox and then detect for Escape key event before calling NavigationService.GoBack(). Here is a piece of code to illustrate my point and the effect you are describing above:
The XAML (SecondPage.xaml):
<TextBox x:Name="SomeTextBox" KeyUp="SomeTextBox_KeyUp"/>
The C# Code-behind:
private void SomeTextBox_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
NavigationService.GoBack();
}
}
Upvotes: 2
Reputation: 1
you can implement the LostFoucs event handler of theTextBox,navigate to the page which you want in the handler.
Upvotes: -2