WP8.1 back button quits the app

2019-07-19 19:03发布

问题:

The last time I developed against Windows Phone, it was with version 8. Now I'm making use of 8.1. Maybe this is a new feature from MS, but when I press the back button on the phone, regardless of how deep I'm into the app, the app minimizes. This is seriously annoying! Is there anything that I can do?

Many thanks in advance! Kind regards,

回答1:

Yes, this is the normal behaviour in Windows Phne 8.1 non-SL apps. Here a workaround to implement in your App.xaml.cs file:

public App()
{
    this.InitializeComponent();   
    HardwareButtons.BackPressed += HardwareButtons_BackPressed;        
}

void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
    Frame rootFrame = Window.Current.Content as Frame;

    if (rootFrame != null && rootFrame.CanGoBack)
    {
        e.Handled = true;
        rootFrame.GoBack();
    }
}