Windows Phone 8.1如何只返回一页? [英] Windows Phone 8.1 How to navigate just one page back?

查看:87
本文介绍了Windows Phone 8.1如何只返回一页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计。我在手机应用程序中挣扎着导航。我已经为我的项目添加了三个空白页面并设法向前导航页面到页面但是......

我想要用户点击手机上的后退按钮返回一页当然,当他再次按下它时,请返回主页面。会发生什么情况,当用户按下设备上的后退按钮时退出应用程序。

这是我默认使用的方法代码:

Hi, guy. I am struggling with navigation in my phone app. I have added three blank pages to my project and managed to navigate forward for page to page but ....
I want a user when click the "back button" on the phone go back just one page and of course when he press it again go back to the main page. What happens is, that at the moment user exits the app when pressing the back button on the device.
This is the code I have got by default in method called:

private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
    if (this.GoBackCommand.CanExecute(null))
    {
        e.Handled = true;
        this.GoBackCommand.Execute(null);
    }
}



这是我试图在该方法中添加的内容,以及我在互联网上发现的但不起作用的内容:


This is what I have tried to put in the method instead, and what I found on internet but didn't work:

if (Frame.CanGoBack)
{
    e.Handled = true;
    Frame.GoBack();
}



和这一个(非常相似)但也没有工作:(


and this one (quite similar) but didn't work either :(

Frame rootFrame = Window.Current.Content as Frame;

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



有人可以帮帮我吗?


Can anyone help me with this, please?

推荐答案

您已经使用 NavigationService.BackStack 来运行前几页。



这是一篇好文章应该让你开始 - 如何使用后台堆栈导航对于Windows Phone 8 [ ^ ]。
You have use NavigationService.BackStack to run through the previous pages.

Here is good article that should get you started - How to navigate using the back stack for Windows Phone 8[^].


我得到了帮助我在另一个论坛上的人的解决方案。将其粘贴在她身上以便它可以帮助其他人。

Ba实际上,当您将BlankPage添加到项目而不是BasicPage时,会遗漏一些内容。以下是您需要在添加的BlankPage后面粘贴/输入代码的内容。您的页面必须订阅

Windows.Phone.UI.Input.HardwareButtons.BackPressed + = HardwareButtons_BackPressed;



在下面的代码中,评论的部分是可选的,取决于你想要使用的东西。



你会的需要引用包含NavigationHelper.cs的common文件夹,我假设你拥有它。



I have solution from someone who helped me on another forum. Pasting it in her so that it might help someone else.
Basically the thing is, when you add "BlankPage" to your project instead of "BasicPage" there is some things missing. Here is what You need to paste/type into your code behind of your added "BlankPage". Your page has to subscribe to
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;

In code below commented parts are optional, depends on what you want to use.

You will be needing reference to your "common" folder which contains NavigationHelper.cs and I assume You have it.

using (yourAppName).Common;







public sealed partial class ListPage : Page
{
    private NavigationHelper navigationHelper;
   // private ObservableDictionary defaultViewModel = new ObservableDictionary();

    public ListPage()
    {
 
        this.InitializeComponent();
        this.navigationHelper = new NavigationHelper(this);
        //this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
       // this.navigationHelper.SaveState += this.NavigationHelper_SaveState;

    }
 
    public NavigationHelper NavigationHelper
    {
        get { return this.navigationHelper; }
    }
 
    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.
    /// This parameter is typically used to configure the page.</param>

    //private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
    //{
    //}

    //private void NavigationHelper_SaveState(object sender, SaveStateEventArgs e)
    //{
    //}







我希望它会帮助别人。玩得开心:)




I hope it will help someone. Have fun:)


这篇关于Windows Phone 8.1如何只返回一页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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