WP8.1 back button quits the app

天涯浪子 提交于 2020-01-04 16:57:08

问题


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();
    }
}


来源:https://stackoverflow.com/questions/28150746/wp8-1-back-button-quits-the-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!