的Windows Phone 8.1通用应用程序终止对从浏览第二页回来? [英] Windows Phone 8.1 Universal App terminates on navigating back from second page?

查看:112
本文介绍了的Windows Phone 8.1通用应用程序终止对从浏览第二页回来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Windows Phone 8.1通用应用程序。2页

I have 2 pages in my Windows Phone 8.1 Universal App.

我从导航的第1页的.xaml为第2页通过一个按钮单击事件code的.xaml:

I navigate from Page1.xaml to Page2.xaml by using a button with the click event code:

this.Frame.Navigate(typeof(Page2));

当我在第二页,我用的是硬件返回按钮的应用程序关闭,不异常或任何东西。它只是返回到启动画面。

When I am on Page2, and I use the hardware back button the app closes without an exception or anything. It just returns to the startscreen.

我已经尝试过以下关于第2页

I already tried the following on Page 2:

public Page2()
    {
        this.InitializeComponent();
        Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
    }

    void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
    {
        Frame.GoBack();
    }

据我知道,我不清除回栈。

As far as I know I do not clear the back stack.

这是怎么回事,我该怎么解决这个问题?

What is going on, and how can I fix this?

亲切的问候,
尼尔斯·

Kind regards, Niels

推荐答案

这是新的Windows Phone 8.1。

This is new to Windows Phone 8.1.

如果您使用的是VS2013模板创建一个新的枢纽通用的应用程序,你会发现在一个叫通用NavigationHelper文件夹中的类。

If you create a new Hub Universal App using a VS2013 template, you'll notice a class in Common folder called a NavigationHelper.

这NavigationHelper指点你如何正确应对备份按钮preSS。所以,如果你不想使用NavigationHelper,这里是如何得到旧的行为后面:

This NavigationHelper gives you a hint how to properly react to back button press. So, if you don't want to use the NavigationHelper, here's how to get the old behavior back:

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

void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
    if (Frame.CanGoBack)
    {
        e.Handled = true;
        Frame.GoBack();
    }
}

您也可以做到这一点的应用水平,以避免去做每一页上:

You can also do it on app level, to avoid having to do it on every page:

public App()
{
    this.InitializeComponent();
    this.Suspending += this.OnSuspending;

    #if WINDOWS_PHONE_APP
    HardwareButtons.BackPressed += HardwareButtons_BackPressed;
    #endif
}

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

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

这篇关于的Windows Phone 8.1通用应用程序终止对从浏览第二页回来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆