-
Back key behavior
I've developed an application with a main screen and a list screen. If I select something from the list, screen, I'm automatically returned to the main screen. However if I press back at this point, I back into the list screen, rather than backing out of the application. Is there a better solution than overriding the back button on that screen to throw an unhandled exception?
-
Re: Back key behavior
Hello Jerry,
As far as I understand your problem you want below mentioned navigation in your application.
[B]S1[/B] = Main screen
[B]S2 [/B]= List screen
[B]Exit [/B]= Exit from
Linear navigation structure:
S1 -> S2 -> S1 -> Exit
For your solution you can use Non-Linear navigation using [B]NavigationService.RemoveBackEntry();[/B] API when you select something from the list screen and automatically returned to the main screen that time you can call this API.
S1 -> S2 -> (select item that time you have to call NavigationService.RemoveBackEntry() this method will remove the S2 stack entry) - > Exit (on Back key Press)
However you can also override OnBackKeyPress method see below.
[code]
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
base.OnBackKeyPress(e);
}
[/code]
-
Re: Back key behavior
using System.Windows.Navigation;
protected override void OnBackKeyPress(CancelEventArgs e)
{
base.OnBackKeyPress(e);
// back button and other navigation no longer work after the e.Cancel = true.
}